(improvement) Add __slots__ to _Frame to eliminate per-instance __dict__ (30-40ns saving, 264 bytes saved per call) - #802
Conversation
Benchmark results (CPython 3.14, 500k iterations)Per-instance memory:
Per-call timing:
Bulk allocation (10k frames):
|
|
Warning Review limit reached
Next review available in: 22 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: QUIET Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Comment |
|
Rebased onto current `origin/master` (was based on an older commit; no conflicts). Per a related discussion on PR #805/#806 about
Conclusion: the Also ran Force-pushed the rebased commit (same single commit, no new commits added). Still a draft. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds __slots__ to the internal _Frame class to avoid per-instance __dict__ allocation, reducing memory usage and improving hot-path performance when parsing response frames.
Changes:
- Add
__slots__to_Framewith its fixed set of attributes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
|
|
||
| class _Frame(object): | ||
| __slots__ = ('version', 'flags', 'stream', 'opcode', 'body_offset', 'end_pos') |
77f28de to
0695572
Compare
_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 <yaniv.kaul@scylladb.com>
0695572 to
3d7f16d
Compare
Summary
Add
__slots__to the_Frameclass incassandra/connection.py. Eliminates per-instance__dict__allocation.Motivation
_Frameis instantiated for every response frame received from the server. It has exactly 6 fixed attributes (version,flags,stream,opcode,body_offset,end_pos) and is never monkey-patched or dynamically extended. Adding__slots__removes the per-instance__dict__, reducing memory pressure on high-throughput workloads.Benchmark (CPython 3.14, per-call)
Memory:
__dict__)__slots__)Timing:
Bulk (10K frames):
Changes
cassandra/connection.py: Add__slots__ = ('version', 'flags', 'stream', 'opcode', 'body_offset', 'end_pos')to_FrameTesting
Unit tests pass (28/28 in test_connection.py). Verified that
_Frameinstances no longer have__dict__.