LearnNewsExamplesConnect
Frontmatter
assigneesneo-gemini-julia
createdAtJul 9, 2025, 12:57 PM
updatedAtNov 5, 2026, 6:48 PM
githubUrlhttps://github.com/neomjs/neo/issues/6997
authortobiu
commentsCount3
parentIssue6992
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtNov 5, 2026, 6:48 PM

Implement Effect Memoization

Closed v13.4.0/archive-v13-4-0-chunk-2 enhancementno auto closeaicore
tobiu
tobiu commented on Jul 9, 2025, 12:57 PM

1. Summary

Enhance the Neo.core.Effect system (or provide a utility around it) to support memoization for VDOM-generating methods. This will significantly improve rendering performance by caching the VDOM output and preventing unnecessary re-executions when component configs (inputs) have not changed.

2. Rationale

Functional components, driven by Neo.core.Effect, re-generate their VDOM whenever a tracked config changes. While efficient, re-generating complex VDOM trees can still be computationally intensive. By memoizing the output of pure VDOM-generating methods, we can avoid redundant work. If the inputs to createVdom() are the same as the last execution, the cached VDOM can be returned directly, bypassing the VDOM generation and worker communication steps.

3. Scope & Implementation Plan

  1. Memoization Mechanism: Design and implement a caching layer for Neo.core.Effect instances (or a new MemoizedEffect class). This mechanism will:
    • Store the last computed VDOM output.
    • Efficiently compare current inputs (tracked configs) with previous inputs to determine if re-execution is necessary.
    • Invalidate the cache when inputs change.
  2. Integration: Determine how developers will opt-in to memoization (e.g., a config on FunctionalBase, a decorator, or a utility function).
  3. Performance Testing: Create benchmarks to measure the performance gains achieved through memoization, especially for components with complex VDOM structures or frequently updated but unchanged inputs.

4. Definition of Done

  • A memoization mechanism for Neo.core.Effect is implemented.
  • Functional components can leverage memoization to improve rendering performance.
  • Performance benchmarks demonstrate measurable gains.

5. Contract Ledger (Intake-Derived)

Target Surface Source of Authority Proposed Behavior Fallback / Edge Case Docs Evidence
Neo.functional.useMemo(fn, dependencies) (src/functional/useMemo.mjs, re-exported via src/functional/_export.mjs) Issue #6997 · Epic #6992 · src/functional/useConfig.mjs (Symbol.for('hooks') / Symbol.for('hookIndex') slot convention) Memoizes the return value of fn() in component[Symbol.for('hooks')][hookIndex++].
• Explicit mode (Array.isArray(dependencies)): inputs are dependencies ∪ trackedConfigs; reuses cached value when dependencies.length matches, every element passes Object.is(next, prev) || Neo.isEqual(next, prev), and every Neo.core.Config read inside fn passes Object.is(cfg.get(), prevVal) || cfg.isEqual(cfg.get(), prevVal) (re-registering each config on the active Effect).
• Automatic mode (dependencies === undefined): tracks Neo.core.Config reads inside fn via EffectManager collector (trackedConfigs.size > 0) and reuses cached value when all tracked configs still pass Object.is(cfg.get(), prevVal) || cfg.isEqual(cfg.get(), prevVal).
• Throws Error("useMemo must be called from within a functional component's createVdom method.") when no active Effect or owning component exists.
• Calling other hooks (useConfig, useEvent, useMemo) inside fn is forbidden (cache hits skip fn, shifting subsequent hook slot indices).
• In automatic mode, plain outer-scope variables captured from createVdom are not tracked unless passed in dependencies.
Yes (src/functional/useMemo.mjs JSDoc, learn/comparisons/NeoVsReact.md) test/playwright/unit/functional/UseMemo.spec.mjs (6 Playwright unit tests including child-component VDOM reconciliation, explicit+Config invalidation, and 8,000-item sort/checksum 30-update interleaved benchmark)
Neo.functional.component.Base#processVdomForComponents & #generateIds (src/functional/component/Base.mjs) Issue #6997 · src/functional/component/Base.mjs:403-547 Preserves existing child component instances in #nextChildComponents when encountering {componentId} references inside cached/memoized VDOM subtrees, and tracks auto-generated VDOM IDs via Symbol.for('vdomAutoId') so generateIds never overwrites {componentId} placeholders on cached renders. Unreferenced child components absent from #nextChildComponents continue to be destroyed in cleanup step 6. Yes (src/functional/component/Base.mjs JSDoc) test/playwright/unit/functional/UseMemo.spec.mjs (preserves child component instances inside a memoized VDOM subtree across unrelated parent re-renders)
tobiu added parent issue #6992 on Jul 9, 2025, 12:57 PM
tobiu added the enhancement label on Jul 9, 2025, 12:57 PM
tobiu removed the stale label on Oct 8, 2025, 11:42 AM
tobiu added the help wanted label on Oct 8, 2025, 11:42 AM
tobiu added the good first issue label on Oct 8, 2025, 11:42 AM
tobiu added the no auto close label on Oct 8, 2025, 11:42 AM
tobiu added the hacktoberfest label on Oct 8, 2025, 11:42 AM