Repository navigation
Commit 4f4ba91
authored
feat(esm): bake analyzable urls where the name settles late (#21828)
* feat(esm): bake analyzable names into content-named chunks
A chunk named by [chunkhash], or by [contenthash] with realContentHash
off, kept the runtime form: the deferred pass rewrites the asset after
its name was taken, and nothing repairs that name afterwards.
Fold what each stand-in resolves to into the consuming chunk's own hash
before the name is taken, so the two move together — the same thing
RuntimeModule.dependentHash already does for __webpack_require__.u. The
bake-order predicate now follows createHash's real rounds (async, then
initial, then runtime, then entry) instead of comparing ids alone, since
a folded name has to be settled first; one direction of a chunk cycle
bakes on that order too.
A stand-in whose prefix carries a public path, a template or an undo
path still needs the repair: those resolve against the compilation hash
or the consuming asset's own name, neither settled while it is hashed.
* perf(esm): cache what the analyzable name fold walks
The fold is asked twice per chunk — once for chunk.hash, once for
contentHash — and each ask walked everything the chunk reaches and
re-resolved every name through getPath. Memoize the folded text per
chunk and the resolved name per chunk and type, and take the second
walk over initial chunks only for a runtime chunk, which is the only
one that writes out a name it does not reference.
Both caches are dead once createHash returns, so afterHash drops them
rather than holding a name per chunk edge until seal.
Counted over a 400-chunk dynamic-import tree: the fold falls from 31.6ms
to 6.1ms, and its share of build cpu from 5.6% to 1.3%. The default
production path (contenthash with realContentHash) stays at 0.1% and
makes no call into the new predicates at all; a build without
output.module never registers the tap.
* feat(esm): bake references a per-asset path used to block
Two more analyzable bailouts, both about text that varies per asset
rather than per build:
A module duplicated into chunks at two output depths needs each copy to
carry its own `../` path to the chunk they share, which only a stand-in
resolved per asset can do. That was refused wherever those chunks were
named by their own content — but the depth is read off the filename
template with the hashes neutralized, exactly as `_chunkPlacement`
already does during code generation, so it reaches the hash before the
name is taken like any other part.
A module in a chunk the host fetched and in one the loader fetched
through `output.publicPath` sits at two urls one public path apart. That
only makes the two disagree where the public path has a depth of its own
— where it has none, both answers put the same text in front, so the
literal is right either way and only a public path that climbs still
keeps the runtime form.
Asking a chunk for its depth during hashing also surfaced a latent
throw: a `chunkFilename` function was handed to `getPath`, which then
had to resolve a `[contenthash]` in what it returned against a hash that
does not exist yet. It is now asked for its template first, and one that
builds a name out of a hash itself gets a stand-in to build from.
* fix(esm): read the base uri off the chunk that sets it
`entryBaseUri` polled every chunk carrying entry options and gave up
when two of them named different bases. But the value a literal has to
agree with is the one `BaseUriRuntimeModule` writes out, and it reads
the entry options off the chunk it is emitted into — so entries sharing
a runtime chunk already share the base it sets, whatever their own
descriptors say.
Under `runtimeChunk: "single"` webpack emits one `__webpack_require__.b`
taken from the first entry, and every entry resolves against it. The
runtime form already did exactly that; now the baked literal spells the
same url instead of refusing, and the runtime module that set the base
drops out because nothing reads it any more.
Entries that really are generated for separate runtimes keep their own
bases, and one source shared across runtimes that disagree still bails.
* feat(esm): bake names built from the compilation hash
A public path or a wasm filename naming `[fullhash]` was refused
wherever the chunk holding the reference is named by its own content
with nothing to repair that name — so a library shipping either could
not be followed statically.
The refusal was self-defeating. Such a chunk normally reaches for
`__webpack_require__.p`, whose runtime module is flagged `fullHash`,
which already puts the chunk in `createHash`'s full-hash round: its
name is taken again once the compilation hash exists. Baking the same
text drops that runtime module and with it the very property that made
the name sound.
So put the chunk there on purpose. After code generation, the chunks
whose bytes will carry that hash are read back out of what was
generated — the stand-in says so itself, which a module restored from
the persistent cache still carries — and each is attached to the
full-hash round with no module to re-render. Its `[chunkhash]` is
remixed with the compilation hash by the existing loop, and its
`[contenthash]` is folded with it in the round that follows.
Nothing may read such a chunk's name, so a content-named chunk in a
build that bakes the hash is not one whose name is baked elsewhere.
Asked of the shape of the build rather than of the marks, which are not
made until code generation is over, so both phases give one answer.
Two wasm cases documented the old refusal and now bake; the case
covering the runtime interpolation keeps it with `devtool: "eval"`,
a reason unrelated to hashing.
* feat(esm): order bakes by when a chunk settles, not by its runtime
Two refusals were standing in for one question. A runtime chunk was
refused outright, because only such a chunk can carry a full-hash
module and so be re-hashed after every round; and a content-named chunk
was refused in any build that bakes the compilation hash, because it
might be moved into that round. Both were guesses at the same thing:
when does this chunk's name settle.
Ask it directly instead. The chunk graph says exactly which chunks
reach that last round, so the order is early-before-late first and the
four rounds after — and a chunk baking a name that settles late is
marked to settle later still, computed to a fixed point since the chunk
it names may be baked somewhere further up in turn. During code
generation, before the marks exist, the answer is the one the marking
will bring about.
That leaves the runtime round, which is ordered by references between
its chunks rather than by id. Mirror the relation `createHash` uses:
an async entrypoint the target reaches is settled before it — which is
a worker's chunk against the chunk spawning it.
A worker's chunk is reached by neither the referenced-chunk walk nor
the initial-chunk one, so the fold now walks the async entrypoints too.
Without that, a chunk baked the worker's name while its own hash stood
still — the watch case added here fails exactly that way.
* feat(esm): bake the last two urls that varied per asset
A protocol-relative entry `baseUri` names a host but no scheme, and was
refused because `new URL(name, "//host/")` cannot be resolved here. But
the runtime does not resolve it here either: it writes
`new URL("//host/", import.meta.url)` and reads the scheme off the
chunk's own url — the very url the literal is resolved against. So the
literal keeps the base protocol-relative and settles the same way at
load time, and the runtime module that set the base drops out.
A module in a chunk the host fetched and in one the loader fetched
through a public path with a depth of its own sits at two urls one
directory apart. Neither literal is right for both, so each asset now
gets its own: a `"unserved"` part the deferred pass resolves against
the chunk it is writing into, putting the public path in front only
where the asset is not already under it. A chunk that is itself served
both ways has no answer of its own and still keeps the runtime form.
`asset-url-mixed-serving` documented the old fallback and now asserts
the two literals — `"./media/asset.txt"` where the host fetched the
chunk and `"../asset.txt"` where webpack did, both naming the same file.
* test(wasm): keep the runtime name without inflating the case
`full-hash-digest-filename` needs a reason to keep the runtime form that
has nothing to do with hashing, and `devtool: "eval"` supplied one by
wrapping every module in an escaped string — which grew each of the
three bundles by ~877 B and each chunk by ~749 B, most of the size the
report attributes to this change.
Reassign `__webpack_public_path__` instead. It says the same thing more
directly — the loader has to build the name at runtime because the path
is chosen there — and the value assigned is the one `auto` computes, so
nothing else moves. The chunks go back to the bytes they had before.
* test(esm): cover the transitive marking and tighten the prose
Review findings:
Comments in `lib/` and `test/` must be at most two short lines; several
of the new ones ran to three or four. Trimmed each to the fact it
carries, with the longer reasoning already in the enclosing JSDoc. The
changeset description is back under 80 characters.
`findBundle` scanned the output directory with `.find`, which yields
`"./undefined"` and an unclear failure if nothing matches. It now takes
the whole match list and names what it found, so a directory holding
other than one bundle fails loudly instead of executing the wrong file.
`fullhash-public-path` reached the fixed-point loop that marks a chunk
late for baking a late name, but never its body: every chunk that baked
one already carried the compilation hash itself and was marked in the
first pass. A middle chunk that only names the one below it — no url of
its own — is the shape that needs the second pass, and it now covers
that loop.
* test(wasm): shorten the public path comment
Three lines where two carry the same fact.
* fix(esm): fold only the names a chunk actually bakes
The fold walked everything the chunk's group reaches, so a split chunk
that references nothing still had its neighbours' names folded in: an
entrypoint's async children are reachable from every chunk sharing that
group. Changing a lazy chunk therefore moved the `splitChunks` vendor
chunk's hash — the opposite of what splitting it out is for.
Use the set the marking pass already reads back off the generated code,
which names exactly the chunks a stand-in here resolves to. It needs no
graph walk, and the worker case it used to take a third walk for is
covered because the payload names that chunk directly.
* fix(runtime): hash a chunk loader by its code under a content-named filename
A runtime module is generated once to be hashed, before any hash exists, so a
chunk loader resolving its own `[contenthash]` name there threw — and
`RuntimeModule.updateHash` swallows that, pinning the module's hash to the
message. The code generation cache then answered a later build with the first
one's source, so a loader that had to grow never reached the asset.
Read the name through `RuntimeTemplate.chunkRootOutputDir`, which neutralizes
the hashes it does not need: they sit in the basename and the `../` depth is
all these five call sites want.
* test(wasm): cover the baked wasm url alongside the runtime-read one
The public-path reassignment that keeps a config on the runtime naming path was
applied to the whole case, so all three configs grew a `get javascript chunk
filename` module the analyzable form had made unnecessary. Gate it per config
and let the first one bake, asserting the literal url in the chunk that holds
the reference — one config back to what it costs on `main`, and a fourth
behaviour covered rather than a third one lost.
Also correct the `base-uri-relative` note that says a protocol-relative base
cannot be spelled as a literal; it bakes.
* test(esm): shorten the fold comment to two lines
* refactor(esm): drop the unused build-bakes-full-hash predicate
Left over from an earlier shape of the full-hash work, where a build-wide answer
gated the stand-ins; marking the chunks that settle late replaced it and nothing
has called it since.1 parent 7651c03 commit 4f4ba91
82 files changed
Lines changed: 1352 additions & 203 deletions
File tree
- .changeset
- lib
- esm
- node
- runtime
- webworker
- test
- configCases
- analyzable
- asset-url-mixed-serving
- chunkhash-name-follows-fill
- chunkhash-name-stays-put
- content-named-single-runtime
- contenthash-without-repair
- fullhash-public-path
- protocol-relative-base-uri
- served-both-ways-with-depth
- served-both-ways
- two-depths-content-named
- nested
- entry/base-uri-relative
- wasm
- analyzable-fullhash-filename
- analyzable-templated-url-public-path
- full-hash-digest-filename
- statsCases/analyzable-esm-fallbacks
- __snapshots__
- watchCases
- chunks/content-named-runtime-loader
- 0
- 1
- long-term-caching
- analyzable-content-named-parent
- 0
- 1
- analyzable-worker-name
- 0
- 1
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 15 | + | |
19 | 16 | | |
20 | 17 | | |
21 | 18 | | |
22 | 19 | | |
23 | | - | |
24 | 20 | | |
25 | 21 | | |
26 | 22 | | |
| |||
146 | 142 | | |
147 | 143 | | |
148 | 144 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 145 | + | |
161 | 146 | | |
162 | 147 | | |
163 | 148 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 13 | + | |
17 | 14 | | |
18 | 15 | | |
19 | 16 | | |
20 | | - | |
21 | 17 | | |
22 | 18 | | |
23 | 19 | | |
| |||
86 | 82 | | |
87 | 83 | | |
88 | 84 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 85 | + | |
101 | 86 | | |
102 | 87 | | |
103 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 13 | + | |
17 | 14 | | |
18 | 15 | | |
19 | 16 | | |
20 | | - | |
21 | 17 | | |
22 | 18 | | |
23 | 19 | | |
| |||
86 | 82 | | |
87 | 83 | | |
88 | 84 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 85 | + | |
101 | 86 | | |
102 | 87 | | |
103 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | 10 | | |
13 | 11 | | |
14 | 12 | | |
| |||
30 | 28 | | |
31 | 29 | | |
32 | 30 | | |
33 | | - | |
| 31 | + | |
34 | 32 | | |
35 | 33 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
| 34 | + | |
| 35 | + | |
49 | 36 | | |
50 | 37 | | |
51 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 13 | + | |
17 | 14 | | |
18 | 15 | | |
19 | 16 | | |
20 | | - | |
21 | 17 | | |
22 | 18 | | |
23 | 19 | | |
| |||
45 | 41 | | |
46 | 42 | | |
47 | 43 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 44 | + | |
| 45 | + | |
58 | 46 | | |
59 | 47 | | |
60 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
20 | 24 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
0 commit comments