Fast-path framework bookkeeping fields in state attribute access

Closed
AL
2mo ago
+7479-274

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 the CLASS_VAR_NAMES fast path. They are never state vars, never inherited, and were never proxied (not in base_vars/backend_vars), so resolution via object.__getattribute__ is behavior-identical; assignments already ended in object.__setattr__ with no dirty-marking.
  • Reorder the proxying condition so base_vars/backend_vars membership is checked before is_mutable_type, sparing non-var values the type check.
  • Cache get_skip_vars() per class as a frozenset, invalidated when inherited_vars changes (_update_substate_inherited_vars, add_var).
  • Cache the frontend computed var names used by get_delta per class, invalidated when computed_vars changes (_evaluate, dynamic route vars).

Benchmarks (GitHub Actions runner, run, 2 passes each)

Casemainthis PRspeedup
4 bookkeeping attr reads3.66 / 3.56 us0.61 / 0.66 us~5.7x
setattr + get_delta + _clean cycle84.4 / 71.4 us54.5 / 51.4 us~1.4x
get_skip_vars()0.49 / 0.48 us0.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