Commit Graph

1 Commits

Author SHA1 Message Date
Nathan Nguyen 88ed49e11d perf(build): cache repeated compatibility transforms (#2578)
* perf(build): cache repeated compatibility transforms

App Router builds run pure dynamic-request and typeof window transforms repeatedly across RSC, SSR, and analysis passes. Re-parsing identical module input adds build work without changing output.

The transform hooks now reuse results for exact module id, source, and environment replacement keys while replacing stale per-id source entries. Focused tests cover cache reuse and key separation.

* perf(build): reuse pure compatibility transforms

Repeated build environments can parse and rewrite the same module source more than once. The transform result is deterministic once the module id, source, and environment-derived variant are fixed.

Share the existing bounded per-module cache across the compatible transform plugins and cover source, module, variant, and null-result boundaries.

* fix(build): invalidate cached source identities after junction retargets

Repeated transforms can keep emitting import.meta.url and CJS globals for a junction's previous canonical target when the raw ID and source stay unchanged.

The import-meta-url cache variant omitted the canonical path even though the rewrite derives its output from that path. Include canonicalId in the variant and cover retargeting between identical source files.

* ci: rerun performance benchmarks

* perf(build): avoid composite import-meta cache keys

Eligible import-meta transforms allocate and hash a composite string containing the canonical root and module path on every invocation, including cache hits. That adds deterministic work to dev cold start.

Keep source, canonical root, and canonical id as direct equality fields in a per-module entry. Retain only the two-value environment result map so canonical-path invalidation remains correct without composite key allocation.

---------

Co-authored-by: James <james@eli.cx>
2026-07-21 22:04:22 +01:00