Commit d1dbc45
committed
Add __slots__ to Tablet and Tablets classes for memory optimization
Implemented __slots__ for tablet-related classes in cassandra/tablets.py
to reduce per-instance memory overhead.
Changes:
- Tablet class: Added __slots__ with 3 attributes (first_token, last_token, replicas)
- Tablets class: Added __slots__ with 2 attributes (_tablets, _lock)
- Removed class-level attribute definitions that conflicted with __slots__
- Preserved and enhanced attribute documentation in class docstrings
Memory Impact:
Each Tablet instance saves approximately 280-300 bytes by eliminating the
per-instance __dict__. Tablet objects are created for each token range in
ScyllaDB tablets-enabled clusters. In a cluster with many tablets, this
optimization significantly reduces the driver's memory footprint.
The Tablets class is typically a singleton per cluster, so the memory
savings are minimal there, but the change maintains consistency with the
optimization pattern and prevents future __dict__ usage.
Testing:
- All 7 tablet-specific unit tests pass
- Verified __dict__ is not created (memory optimization confirmed)
- No functionality changes or regressions
Signed-off-by: Yaniv Kaul <yaniv.kaul@scylladb.com>1 parent bed473c commit d1dbc45
1 file changed
+14
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
11 | 16 | | |
12 | | - | |
13 | | - | |
14 | | - | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
| |||
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
45 | | - | |
46 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
47 | 56 | | |
48 | 57 | | |
49 | 58 | | |
| |||
0 commit comments