"vscode:/vscode.git/clone" did not exist on "2435ea7ed5c3a7d058cc6f6d649316e96976acaa"
Unverified Commit 57c84ff1 authored by cong-or's avatar cong-or Committed by GitHub
Browse files

perf: add __slots__ to KVCacheBlock (#36164)


Signed-off-by: default avatarcong-or <conchubhar.gannon@gmail.com>
parent e68de8ad
...@@ -202,6 +202,18 @@ def test_kv_cache_block(): ...@@ -202,6 +202,18 @@ def test_kv_cache_block():
assert block.block_hash is None assert block.block_hash is None
def test_kv_cache_block_uses_slots():
block = KVCacheBlock(block_id=0)
# Slots eliminate per-instance __dict__, saving ~264 bytes per block.
# At 100K+ blocks this avoids tens of MB of overhead and GC pressure.
assert not hasattr(block, "__dict__")
# Verify that slots actually prevent dynamic attribute assignment.
with pytest.raises(AttributeError):
block.unexpected_field = True
def test_free_kv_cache_block_queue_initialization(): def test_free_kv_cache_block_queue_initialization():
# Test with a single block # Test with a single block
block = KVCacheBlock(block_id=0) block = KVCacheBlock(block_id=0)
......
...@@ -106,7 +106,7 @@ def init_none_hash(hash_fn: Callable[[Any], bytes]): ...@@ -106,7 +106,7 @@ def init_none_hash(hash_fn: Callable[[Any], bytes]):
NONE_HASH = BlockHash(hash_fn(hash_seed)) NONE_HASH = BlockHash(hash_fn(hash_seed))
@dataclass @dataclass(slots=True)
class KVCacheBlock: class KVCacheBlock:
"""KV-cache block metadata.""" """KV-cache block metadata."""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment