Skip to content

fix(swc): key optimizer env cache by configured values - #12166

Open
David Murdoch (davidmurdoch) wants to merge 2 commits into
swc-project:mainfrom
davidmurdoch:fix/optimizer-globals-cache
Open

fix(swc): key optimizer env cache by configured values#12166
David Murdoch (davidmurdoch) wants to merge 2 commits into
swc-project:mainfrom
davidmurdoch:fix/optimizer-globals-cache

Conversation

@davidmurdoch

Copy link
Copy Markdown
Contributor

Description:

GlobalPassOption::build stores parsed jsc.transform.optimizer.globals.envs maps in a process-wide cache, but the cache key is currently built from globals.vars. Two compilations with the same vars and different explicit envs maps therefore collide, causing the later compilation to reuse stale environment replacements from the earlier one.

Build the cache key from the configured environment map instead, and sort its entries so equivalent maps produce the same key regardless of iteration order.

This was discovered while investigating the cached-span source-map issue fixed by #12129, but it is a separate cache-key bug.

The regression test compiles the same source twice in one process with different explicit environment values. Before the fix, the second compilation incorrectly emits the first value.

Tests:

  • cargo fmt --all -- --check
  • cargo clippy -p swc --all-targets -- -D warnings
  • cargo test -p swc --lib
  • cargo test -p swc --test simple
  • cargo test -p swc --test simple --features react-compiler
  • cargo test -p swc --test rust_api
  • cargo test -p swc --test source_map define_source_map_is_stable_across_compilations -- --exact

Related issue (if exists):

Follow-up to #12129.

@changeset-bot

changeset-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 25d8a40

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-28T23:17:23.991664Z 25d8a40 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codspeed-hq

codspeed-hq Bot commented Aug 28, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 200 untouched benchmarks
⏩ 61 skipped benchmarks1


Comparing davidmurdoch:fix/optimizer-globals-cache (25d8a40) with main (e876e80)

Open in CodSpeed

Footnotes

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

Development

Successfully merging this pull request may close these issues.

1 participant