From 40284664b914eb589878314773e5237b3ef8433e 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. --- cassandra/connection.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cassandra/connection.py b/cassandra/connection.py index 72b273ec37..95fe47679f 100644 --- a/cassandra/connection.py +++ b/cassandra/connection.py @@ -486,6 +486,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