Skip to content

Extend rx.memo configuration and function memoization - #7084

Draft
masenf wants to merge 11 commits into
mainfrom
codex/extend-rx-memo
Draft

masenf wants to merge 11 commits into
mainfrom
codex/extend-rx-memo

Conversation

@masenf

@masenf masenf commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Extend @rx.memo with by_value, recursive, and a validated JavaScript-safe name override. Component memos default to React memoization; Var-returning memos now cache results by argument identity. wrapper=None emits a plain component or function, and by_value=True composes with custom wrappers.

Packed function signatures (children or RestProp) key the identity cache by sorted prop names and their value identities, so newly allocated transport objects do not cause cache misses. Name validation accepts interior $ characters.

recursive=True enables nested auto-memoization for parameterless component bodies and caller-supplied children. Parameterized bodies currently remain in their enclosing scope to prevent extracted components from referencing unbound parameters. Full parameter capture and forwarding remains follow-up work. Function memos reject recursive=True.

Includes documentation, changelog fragments, generated stub hashes, regression tests, and compatibility with the current pure-IIFE component output on main.

Validation

  • 275 focused memo, cross-module, and naming tests passed, including the Node runtime cache regression.
  • Full unit run: 9,259 passed, 20 skipped, and 18 failures caused by the shell's Node 18 runtime. All 18 passed on rerun with Node 24.15.0; coverage was 78.48%.
  • uv run --no-sync pyright reflex tests: no errors.
  • Repository-wide Ruff check and format check passed.

Limitations

  • by_value compares serialized values using JSON.stringify, with its serialization limitations.
  • Function memo caches persist for the module lifetime and grow with unique argument tuples.

Type of change

  • New feature
  • Documentation update
  • Regression tests and local lint/type validation

Review in cubic

@greptile-apps

greptile-apps Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with previous findings addressed and no new blocking issues identified.

Summary

Extends rx.memo with value-based comparison, recursive component memoization, explicit names, and configurable wrappers for Var-returning functions.

  • Function memos cache results by argument identity, including logical values from packed signatures.
  • Recursive extraction preserves parameter scope by keeping parameterized memo bodies intact.
  • Adds documentation and regression coverage for wrappers, naming, caching, and recursive boundaries.
  • Previous findings are addressed; no new actionable findings were identified.

Reviews (6) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..."

Comment thread reflex/compiler/compiler.py
Comment thread packages/reflex-base/src/reflex_base/components/memo.py Outdated
Comment thread packages/reflex-base/src/reflex_base/components/memo.py Outdated
@codspeed

codspeed Bot commented Sep 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 53 untouched benchmarks
⏩ 9 skipped benchmarks1


Comparing codex/extend-rx-memo (852cec5) with main (aaa44a0)

Open in CodSpeed

Footnotes

  1. 9 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.

Comment thread tests/units/compiler/test_memoize_plugin.py Outdated
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