Skip to content

Reuse normalization of unchanged literal app styles - #7059

Draft
Alek99 wants to merge 1 commit into
mainfrom
codex/perf-shared-style-normalization
Draft

Reuse normalization of unchanged literal app styles#7059
Alek99 wants to merge 1 commit into
mainfrom
codex/perf-shared-style-normalization

Conversation

@Alek99

@Alek99 Alek99 commented Sep 7, 2026

Copy link
Copy Markdown
Member

Pages with many components sharing App.style rules 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:

  • Full unit suite: 8,312 passed, 18 skipped, 76.00% coverage; final exact-type eligibility refinement also passed all 47 focused compiler/cache tests.
  • Regressions cover source mutation/replacement, nested container ownership, metadata, signed zero, custom types and override compatibility.
  • Shared-style compile benchmark, repository-wide Ruff and Pyright, and stub generation passed.

Independent of the other performance drafts; based directly on main.

Review in cubic

@greptile-apps

greptile-apps Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces page-local reuse of unchanged literal App.style normalization while preserving source-mutation detection, independently owned nested containers, reactive metadata, and compatibility with component and plugin overrides.

  • Adds a literal-style snapshot key and page-scoped normalization cache.
  • Threads the cache through the default app-style compiler plugin without changing custom override calls.
  • Adds focused coverage for mutations, metadata, breakpoint configuration, custom types, precedence, signed zero, and container ownership.
  • Adds a representative shared-style compilation benchmark and performance news fragments.

Confidence Score: 5/5

The 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.

Important Files Changed

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

@codspeed-hq

codspeed-hq Bot commented Sep 7, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

βœ… 32 untouched benchmarks
πŸ†• 1 new benchmark
⏩ 8 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
πŸ†• test_compile_shared_app_styles N/A 315 ms N/A

Comparing codex/perf-shared-style-normalization (a66bb75) with main (c49a85d)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant