Skip to content

Commit 95befee

Browse files
danceratopzmarioevz
authored andcommitted
perf: add slots=True to compatible dataclasses
Add slots to dataclasses that don't have class variable access conflicts. Optimizes memory usage and attribute access speed for Trie, Case, and TestInfo classes that are frequently instantiated during test execution.
1 parent 05e221c commit 95befee

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/ethereum_test_fixtures/collector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .file import Fixtures
1919

2020

21-
@dataclass(kw_only=True)
21+
@dataclass(kw_only=True, slots=True)
2222
class TestInfo:
2323
"""Contains test information from the current node."""
2424

src/ethereum_test_tools/code/generators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def __new__(
265265
return super().__new__(cls, bytecode)
266266

267267

268-
@dataclass(kw_only=True)
268+
@dataclass(kw_only=True, slots=True)
269269
class Case:
270270
"""
271271
Small helper class to represent a single, generic case in a `Switch` cases

src/ethereum_test_types/trie.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def encode_node(node: Node, storage_root: Optional[Bytes] = None) -> Bytes:
187187
raise AssertionError(f"encoding for {type(node)} is not currently implemented")
188188

189189

190-
@dataclass
190+
@dataclass(slots=True)
191191
class Trie(Generic[K, V]):
192192
"""The Merkle Trie."""
193193

0 commit comments

Comments
 (0)