improve delta perf
Merged
BE
10d ago+137+137+012345678901234567890123456789-2-2-0123456789
Summary
build_deltaandBaseState.dict()read a field that is stored on the state straight from the instance__dict__, instead of callingget_value()for every var.- A computed var, or a field whose default was never stored, still goes through
get_value(). - The result is the same. For a field declared on the state's own class,
get_value()reads the same__dict__entry. A field inherited from a parent state is stored on the parent instance, so it is not in the child's__dict__and takes the old path.
Measurement
BaseState.dict()on a state with 20 fields: 5.3 → 2.85 µs.dict()on a tree of 20 substates: 27.9 → 20.4 µs.- CodSpeed:
test_hydration_snapshot[200]+35%,test_hydration_snapshot[20]+30%,test_computed_dependency_fanout[0]+10%.
Test plan
-
test_build_delta_reads_stored_fields_from_instance_dict,test_build_delta_stores_default_of_unread_fieldandtest_build_delta_sends_inherited_var_under_its_ownercover the fast path, the default and the inherited fallback inbuild_delta -
test_dict_reads_stored_fields_from_instance_dictcoversBaseState.dict() -
uv run pytest tests/units -
ruff check,ruff format --check,pyright
🤖 Generated with Claude Code