Skip to content

Commit 1cdc668

Browse files
committed
perf: store Tablet.replicas as tuple instead of list
Replicas are never mutated after Tablet construction; convert to tuple in __init__ to save 8 bytes per tablet (list overallocates for future appends that never happen) and communicate immutability. Before: 328 bytes/tablet (replicas container: 80 bytes as list) After: 320 bytes/tablet (replicas container: 72 bytes as tuple) Saving: 8 bytes/tablet (2.4%) Combined with __slots__ (commit 1), total savings so far: 96 bytes/tablet. Scale impact (3 replicas/tablet): 128,000 tablets: saves ~1.0 MB (tuple) + 10.7 MB (slots) = 11.7 MB total 256,000 tablets: saves ~2.0 MB (tuple) + 21.5 MB (slots) = 23.5 MB total
1 parent 9b843f2 commit 1cdc668

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

cassandra/tablets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Tablet(object):
2020
def __init__(self, first_token=0, last_token=0, replicas=None):
2121
self.first_token = first_token
2222
self.last_token = last_token
23-
self.replicas = replicas
23+
self.replicas = tuple(replicas) if replicas is not None else None
2424

2525
def __str__(self):
2626
return "<Tablet: first_token=%s last_token=%s replicas=%s>" \

0 commit comments

Comments
 (0)