From 3d7f16d116d2239d18456febbfbefd5b503be07f Mon Sep 17 00:00:00 2001 From: Yaniv Michael Kaul Date: Mon, 6 Apr 2026 21:40:52 +0300 Subject: [PATCH] perf: add __slots__ to _Frame to eliminate per-instance __dict__ _Frame is instantiated for every response frame received from the server. Adding __slots__ eliminates the per-instance __dict__ allocation (~104 bytes on CPython), reducing memory pressure on high-throughput workloads. _Frame only has 6 fixed attributes (version, flags, stream, opcode, body_offset, end_pos) and is never monkey-patched or dynamically extended. Signed-off-by: Yaniv Kaul --- cassandra/connection.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cassandra/connection.py b/cassandra/connection.py index ac2578a16c..6df8c20527 100644 --- a/cassandra/connection.py +++ b/cassandra/connection.py @@ -485,6 +485,8 @@ def __repr__(self): class _Frame(object): + __slots__ = ('version', 'flags', 'stream', 'opcode', 'body_offset', 'end_pos') + def __init__(self, version, flags, stream, opcode, body_offset, end_pos): self.version = version self.flags = flags