fix(terser): share nameCache between chunks by serializing minify tasks - #2020
Open
itsjamie wants to merge 1 commit into
Open
fix(terser): share nameCache between chunks by serializing minify tasks#2020itsjamie wants to merge 1 commit into
itsjamie wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rollup Plugin Name:
terserThis PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
resolves #1970
Description
The plugin already returns the mutated
nameCachefrom its workers and merges it back, but the merge never takes effect across chunks. Rollup callsrenderChunkfor every chunk concurrently, so each chunk's options are serialized with the still-empty cache before any other chunk's cache comes back.maxWorkers: 1doesn't help because the pool dispatches the next queued task synchronously from the worker'smessagehandler, before the awaiting merge-back microtask runs. The result is the divergence in #1970: the same method mangled to.o()in one chunk and.m()in another.Sharing a name cache only works if each
minify()call sees the names the previous call assigned, so whennameCacheis provided the minify tasks now run through a promise chain: each chunk's options are snapshotted and serialized only after the previous chunk's cache has been merged back. Builds without anameCachekeep the current parallel behaviour.Tests cover a shared cache across two entries importing a common module (the shape from the issue) and across two unrelated entries, each with default workers and with
maxWorkers: 1. Two more tests pin the surrounding behaviour: without anameCacheunrelated chunks still mangle independently, and with one the build uses a single worker even whenmaxWorkers: 4is set.A side effect worth a second look: a shared
nameCachenow effectively serializes the whole build onto one worker. I documented that in the README rather than emitting a runtime warning. Open to thoughts on whether it deserves more than a docs note.