From 91a160166b29714d57dc149050080b6f7be82d3d Mon Sep 17 00:00:00 2001 From: Yaniv Michael Kaul Date: Fri, 6 Mar 2026 10:53:06 +0200 Subject: [PATCH] (improvement) cluster: cache parsed tablet routing type in ResponseFuture The _set_result() method re-parses the same complex TupleType string on every query result that includes tablet routing info. Cache the parsed type as a class attribute on ResponseFuture so lookup_casstype() is only called once for the lifetime of the process. --- cassandra/cluster.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cassandra/cluster.py b/cassandra/cluster.py index 622b706330..51d0b2d88b 100644 --- a/cassandra/cluster.py +++ b/cassandra/cluster.py @@ -4345,6 +4345,7 @@ class ResponseFuture(object): _spec_execution_plan = NoSpeculativeExecutionPlan() _continuous_paging_session = None _host = None + _TABLET_ROUTING_CTYPE = None _warned_timeout = False @@ -4642,7 +4643,10 @@ def _set_result(self, host, connection, pool, response): if self._custom_payload and self.session.cluster.control_connection._tablets_routing_v1 and 'tablets-routing-v1' in self._custom_payload: protocol = self.session.cluster.protocol_version info = self._custom_payload.get('tablets-routing-v1') - ctype = types.lookup_casstype('TupleType(LongType, LongType, ListType(TupleType(UUIDType, Int32Type)))') + ctype = ResponseFuture._TABLET_ROUTING_CTYPE + if ctype is None: + ctype = types.lookup_casstype('TupleType(LongType, LongType, ListType(TupleType(UUIDType, Int32Type)))') + ResponseFuture._TABLET_ROUTING_CTYPE = ctype tablet_routing_info = ctype.from_binary(info, protocol) first_token = tablet_routing_info[0] last_token = tablet_routing_info[1]