Skip to content

perf(expr): reuse validated results within bounded working sets - #1466

Open
eliasx45 wants to merge 2 commits into
storytold:mainfrom
eliasx45:codex/expression-pr
Open

eliasx45 wants to merge 2 commits into
storytold:mainfrom
eliasx45:codex/expression-pr

Conversation

@eliasx45

@eliasx45 eliasx45 commented Oct 14, 2026 •

Copy link
Copy Markdown

Expressions that repeatedly read other properties rerun scripts and rebuild host data unnecessarily. This PR extracts the expression-performance work from #856 into an independent change against current main, then extends its bounded result memo to retain graph-sized working sets. This PR has no media/audio, GPU residency, UI, dependency or manifest changes.

What changes

  • Collect multiple unresolved host reads per pass, prefetch previously observed reads, and load keyframe arrays only when the keyframe API asks for them.
  • Reuse successful expression results only after validating their recorded host answers. Native impurity tracking bypasses memoization for Math.random and Date, including computed access, aliases and prototype access; existing cycle/time limits remain.
  • Allow up to 65,536 small results within a 32 MiB estimated retained-storage budget per thread, account for payload and table capacity, and reuse bounded table storage on clears. Validated hits skip unused metadata preparation.
  • Compute shape sourceRectAtTime bounds without rasterizing, using the same buffer-extent calculation as rendering.
  • Include synthetic regression coverage and a standalone profiling probe; no third-party assets or new dependencies.

Measurements and limits

The cache-capacity follow-up was measured on a local development integration, not rerun on this upstream adaptation. For repeated sweeps of 20 expression properties (28,800 evaluations), the standalone probe improved from 300.97 → 21.02 ms p50 and 321.80 → 26.66 ms p95. Numeric checksums matched at 1/4/8/20/50 properties. Peak diagnostic-process RSS rose from 27.36 → 57.58 MiB. The 50-property working set still exceeds the cache and still executes every script.

These are CPU evaluator measurements, not input-to-visible-frame latency or a whole-PR speedup claim. The budget estimates retained memo storage, not allocator RSS or total app RAM, and is per thread. Methodology and the full table: docs/expression-cache-performance.md.

Validation

  • Passed strict native Clippy (including compilation of test targets): cargo clippy -p effectcraft-expr -p effectcraft-render --all-targets -- -D warnings.
  • Passed cargo check -p effectcraft-expr -p effectcraft-render --target wasm32-unknown-unknown.
  • Passed rustfmt --check on all changed Rust files and git diff --check.
  • Behavioral regression tests were compiled, not executed under the contributor's daytime build policy. Earlier local performance/checksum probes executed as described above; full CI and live-application QA were not run for this upstream adaptation.

This is the expression-only alternative to the broader held #856, including its expression prerequisites so it can be reviewed and merged independently.

Review follow-up

Integrated current upstream main and fixed clock access through property descriptors, including Object.getOwnPropertyDescriptor(Date, "now").value(). The captured native clock function is wrapped before exposure so aliases and descriptors cannot bypass impurity tracking. Added a deterministic script-run-count regression.

Final-tree formatting and strict workspace/all-target release Clippy passed. Exact old/fixed clock-wrapper probes reproduced the bypass and verified the fix in Node and Boa. Full behavioral tests and fresh performance benchmarks were not run for this update.

Extract the expression-only performance pipeline from storytold#856, preserve native impurity tracking, and retain graph-sized memo working sets with full estimated storage accounting.

Validated native all-target strict Clippy, focused WASM check, formatting and diff checks. Behavioral regression tests compiled but not executed under daytime policy. Earlier local evaluator performance/checksum measurements are documented with provenance.

This branch has not been deployed

No deployments
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