Reuse normalization of unchanged literal app styles - #7059
Conversation
Greptile SummaryThis PR introduces page-local reuse of unchanged literal
Confidence Score: 5/5The PR appears safe to merge, with no concrete correctness, security, or repository-rule violations identified. Cache eligibility is restricted to deterministic exact literal types, mutable normalized containers are copied per component, dynamic and configuration-sensitive values remain uncached, and override compatibility is explicitly preserved and tested.
|
| Filename | Overview |
|---|---|
| reflex/compiler/plugins/_style.py | Adds a page-local cache with mutation-sensitive literal keys and recursively copied mutable containers; no correctness issue was identified. |
| reflex/compiler/plugins/builtin.py | Integrates cached normalization into the default style plugin while preserving existing override signatures. |
| packages/reflex-base/src/reflex_base/components/component.py | Adds an internal style factory hook to app-level component-style lookup without changing default behavior. |
| tests/units/compiler/test_style_cache.py | Covers cache invalidation, output equivalence, metadata, breakpoint changes, custom values, type distinctions, and signed zero. |
| tests/units/compiler/test_plugins.py | Verifies reuse during a page walk, rule replacement and mutation, precedence, independent containers, and override compatibility. |
| tests/benchmarks/test_compilation.py | Adds a benchmark for compilation of many components sharing nested and responsive app styles. |
Reviews (1): Last reviewed commit: "Reuse normalization of unchanged literal..." | Re-trigger Greptile
Merging this PR will not alter performance
Performance Changes
Comparing Footnotes
|
Pages with many components sharing
App.stylerules repeatedly normalize the same CSS keys, responsive arrays and literal values. Reuse unchanged literal rule normalization during each page walk, recheck source contents for mutations, and give each component independent nested containers. Dynamic/custom rules and component/plugin overrides keep their existing behavior.On a fresh 500-card dashboard with shared responsive/nested styles, Python evaluation and compilation fell from 292.26 ms to 259.11 ms (11.3%). This is the median of nine alternating pairs against main on Python 3.14.5 / Apple M5 Pro, with GC collected outside each sample and enabled during compilation. Generated page JavaScript is byte-identical. This excludes startup and frontend bundling.
Validation:
Independent of the other performance drafts; based directly on main.