Skip to content

Commit a74609a

Browse files
committed
perf: add __slots__ to Tablet to eliminate per-instance __dict__
Add __slots__ to the Tablet class, removing the per-instance __dict__ allocation. Tablets are created frequently (one per token range per table) and are long-lived, so the cumulative memory savings are significant. Before: 416 bytes/tablet (48 instance + 96 __dict__ + 80 replicas + 192 tuples) After: 328 bytes/tablet (56 instance + 0 __dict__ + 80 replicas + 192 tuples) Saving: 88 bytes/tablet (21%) Scale impact (3 replicas/tablet): 12,800 tablets (100 tables x 128): saves 1.1 MB 128,000 tablets (1000 tables x 128): saves 10.7 MB 256,000 tablets (1000 tables x 256): saves 21.5 MB Tablet.from_row construction also improves: Before: 186 ns/call After: 147 ns/call (1.27x faster, -21%)
1 parent 5094118 commit a74609a

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

cassandra/tablets.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class Tablet(object):
1515
It stores information about each replica, its host and shard,
1616
and the token interval in the format (first_token, last_token].
1717
"""
18-
first_token = 0
19-
last_token = 0
20-
replicas = None
18+
__slots__ = ('first_token', 'last_token', 'replicas')
2119

2220
def __init__(self, first_token=0, last_token=0, replicas=None):
2321
self.first_token = first_token

0 commit comments

Comments
 (0)