perf: lazy default resolution for component fields#6576
Conversation
Promote ``ComponentField`` to a non-data descriptor so unset attributes fall back to their default on read instead of being eagerly materialized on every instance during ``__init__``. Cache ``get_event_triggers`` per class and memoize ``to_camel_case`` to cut repeated work on the hot component-creation path.
Merging this PR will improve performance by 17.26%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
Greptile SummaryThis PR makes the component hot path leaner by converting
Confidence Score: 4/5Safe to merge; the behavioral change from eager to lazy default materialization is logically sound and the existing eq, copy, and field-enumeration paths all use getattr/get_fields rather than iterating instance.dict, so they remain correct. The core descriptor mechanics are implemented correctly — non-data descriptor ordering, factory-default caching, and class-level trigger caching all work as intended. The minor findings do not affect correctness today but leave small fragility worth tidying before this lands on a high-traffic path. packages/reflex-base/src/reflex_base/components/component.py — specifically the _finalize_fields descriptor-installation condition and the _event_triggers_cache sentinel check. Important Files Changed
Reviews (1): Last reviewed commit: "perf: lazy default resolution for compon..." | Re-trigger Greptile |
Promote
ComponentFieldto a non-data descriptor so unset attributes fall back to their default on read instead of being eagerly materialized on every instance during__init__. Cacheget_event_triggersper class and memoizeto_camel_caseto cut repeated work on the hot component-creation path.All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission:
Changes To Core Features: