Fast-path framework bookkeeping fields in state attribute access
Closed
AL
2mo ago+7479+7479+0123456789012345678901234567890123456789-274-274-012345678901234567890123456789
Linear: ENG-10096
Description
_get_attribute was ~43% of profiled event-handling time, and much of that was the framework's own reads of dirty_vars, parent_state, substates, and _backend_vars paying the full inherited-vars/event-handler/proxying chain on every access from _mark_dirty/_clean/get_delta.
- Add those names (plus
dirty_substates) to theCLASS_VAR_NAMESfast path. They are never state vars, never inherited, and were never proxied (not inbase_vars/backend_vars), so resolution viaobject.__getattribute__is behavior-identical; assignments already ended inobject.__setattr__with no dirty-marking. - Reorder the proxying condition so
base_vars/backend_varsmembership is checked beforeis_mutable_type, sparing non-var values the type check. - Cache
get_skip_vars()per class as a frozenset, invalidated wheninherited_varschanges (_update_substate_inherited_vars,add_var). - Cache the frontend computed var names used by
get_deltaper class, invalidated whencomputed_varschanges (_evaluate, dynamic route vars).
Benchmarks (GitHub Actions runner, run, 2 passes each)
| Case | main | this PR | speedup |
|---|---|---|---|
| 4 bookkeeping attr reads | 3.66 / 3.56 us | 0.61 / 0.66 us | ~5.7x |
| setattr + get_delta + _clean cycle | 84.4 / 71.4 us | 54.5 / 51.4 us | ~1.4x |
| get_skip_vars() | 0.49 / 0.48 us | 0.15 / 0.15 us | ~3.3x |
cProfile (5000 bookkeeping reads + 500 event cycles): _get_attribute tottime drops 0.120s -> 0.061s; total function calls drop 256k -> 207k.
Type of change
- Bug fix (non-breaking change which fixes an issue)
Changes To Core Features:
- Have you added an explanation of what your changes do and why you'd like us to include them?
- Have you written new tests for your core changes, as applicable?
test_get_skip_vars_cached_per_class: per-class caching with inherited vars included and no cross-class leakage.test_frontend_computed_var_names_cached_per_class: backend computed vars excluded; cached identity.test_framework_bookkeeping_fields_not_proxied: bookkeeping containers stay raw while real state vars still get proxied.
- Have you successfully ran tests with your changes locally?
š¤ Generated with Claude Code
https://claude.ai/code/session_01G8cXh3TUbNtbjm2ERqE62X
Generated by Claude Code