Skip to content

Commit 484c91f

Browse files
committed
bench: drop the warm metadata walk from the hydration benchmarks
test_hydration_metadata re-read the cached name, full name, parent and root of every class in a 20- and a 200-substate tree. It came in with #7064 to show the per-class metadata cache replacing the lru_cache whose 128-entry capacity the 200-class tree thrashed. With that cache in place both sizes measure the same cache-hit path, and that path is almost entirely CPython's type attribute cache and call specialization rather than reflex code. That makes it flip on CodSpeed with no related change: [200] alternates between 1.7 and 1.8 ms (-6.9% on #7502, -7.7% on #7501), [20] between 207.6 and 216.7 us (-4.2% on #7410 and #7434, +4.3% on the changelog-only #7445), while every other benchmark reports untouched. Reproduced under callgrind with the same pytest-codspeed instrumentation CI uses. Two runs of the module alone are byte-identical: 1,420,889 Ir for [200]. Running test_state_access.py or test_state_delta.py first in the same process gives 1,363,413 and 1,306,760 Ir (-4.0%, -8.0%) for the unchanged function, while test_hydration_snapshot[200] moves about 1% (5,335,449 to 5,392,507). The count depends on what the process did before the benchmark, not on the code it measures, so no restructuring of the body would settle it. test_hydration_snapshot stays: it walks the same metadata on its way to serializing the tree, so a regression in the metadata path still shows up there, diluted by real work enough to sit under the threshold when nothing changed. The two removed benchmarks show as skipped on CodSpeed until they are archived in the project settings. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011LZPUJkHZur6LUinHeFpZT
1 parent 62d454f commit 484c91f

1 file changed

Lines changed: 9 additions & 25 deletions

File tree

‎tests/benchmarks/test_state_hydration.py‎

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
"""Track state-tree hydration costs below and above the metadata LRU capacity."""
1+
"""Track complete snapshots of small and large state trees.
2+
3+
A snapshot resolves every substate's full name through the per-class metadata
4+
caches (name and parent) on its way to serializing it, so a regression in those
5+
caches shows up here too. A separate benchmark that only re-read the cached
6+
metadata was dropped: with no serialization work to dilute them, CPython's
7+
attribute-cache and specialization costs dominated, and those move several
8+
percent with whatever ran earlier in the process.
9+
"""
210

311
import pytest
412
from pytest_codspeed import BenchmarkFixture
@@ -42,27 +50,3 @@ def test_hydration_snapshot(
4250
benchmark: The benchmark fixture.
4351
"""
4452
benchmark(hydration_state.dict)
45-
46-
47-
def test_hydration_metadata(
48-
hydration_state: BaseState, benchmark: BenchmarkFixture
49-
) -> None:
50-
"""Measure repeated metadata walks without state serialization costs.
51-
52-
Args:
53-
hydration_state: The populated tree whose classes to visit.
54-
benchmark: The benchmark fixture.
55-
"""
56-
classes = [
57-
type(hydration_state),
58-
*(type(s) for s in hydration_state.substates.values()),
59-
]
60-
61-
@benchmark
62-
def walk() -> None:
63-
"""Visit the metadata used to fetch and reconnect a state tree."""
64-
for cls in classes:
65-
cls.get_name()
66-
cls.get_full_name()
67-
cls.get_parent_state()
68-
cls.get_root_state()

0 commit comments

Comments
 (0)