From 06ac8c5e524b69f940f1f8ab69c64d68ba73501e 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cassandra/connection.py b/cassandra/connection.py index d0a75818b2..fc9b22b381 100644 --- a/cassandra/connection.py +++ b/cassandra/connection.py @@ -496,6 +496,15 @@ 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