Repository navigation
Commit ff27449
authored
perf(runtime): emit less generated runtime code (#21803)
* perf(runtime): emit less generated runtime code
Dynamic imports now take an arrow callback instead of a bound
`__webpack_require__`, and five runtime helpers drop code an
`output.environment` flag or the ES5 baseline already guarantees:
- `moduleNamespacePromise` renders `() => (__webpack_require__(id))`
where arrows are available; the bound form stays for ES5, where it is
shorter.
- `__webpack_require__.r` skips the `Symbol.toStringTag` feature test
when `output.environment.symbol` is set, which promises it.
- `__webpack_require__.g` is `globalThis` when
`output.environment.globalThis` is set.
- `__webpack_require__.d` builds one descriptor instead of repeating
`Object.defineProperty` per branch.
- `__webpack_require__.t` reads `Object.getPrototypeOf` directly; its
`__proto__` fallback was dead next to `Object.create`.
- auto `publicPath` strips the `blob:` prefix and the query/fragment in
one pass.
Over `test/configCases`, 1937 assets change: -18.85 KiB gzip and
-180.22 KiB raw, with error counts and runtime module sets unchanged.
* fix(runtime): stop __webpack_require__.O gating every deferred handler
`&` binds looser than `===`, so the guard `priority & 1 === 0` parsed as
`priority & (1 === 0)` and was always 0. Every deferred handler therefore
waited for lower priorities to run first, where `RuntimeGlobals` documents
only an odd priority as waiting.
Webpack's own output is unaffected: it emits priority 0 (entry startup) and
5 (startup prefetch) only, and for those the two readings agree — `5` is odd,
and for `0` the fallback `notFulfilled >= 0` already holds because
`notFulfilled` starts at `Infinity` and priorities are documented as `>= 0`.
It shows up for a plugin registering an even, non-zero priority, which the
new config case does.
* perf(runtime): trim more of the generated chunk-loading code
- The chunk-filename helper is a concise arrow when no chunk carries a
static url, so the common `__webpack_require__.u` is the template
expression alone rather than a block with a `return`.
- The jsonp loader passes the chunk url straight to `__webpack_require__.l`
instead of binding a single-use `const`.
- The ESM chunk installer marks a chunk installed through the `chunkId` it
already read, not by indexing the id list a second time.
- The auto-publicPath regexp drops an escape a character class does not need.
`emptyFunction` keeps its named parameter, with a note: `() => {}` reads
tidier but minifies a byte longer than `x => {}`, which is why it is there.
* test: record the smaller entryB.js in the Stats inline snapshots
`Stats.test.js` pins the emitted size of `entryB.js`, which the runtime
changes take from 3320 to 3184 bytes. It is a `*.test.js` file, so only
the integration matrix runs it — `test:basic` never reaches it.
* chore: shorten the changesets and comments this PR adds
AGENTS.md caps a changeset description at 80 characters and a comment in
`lib/` or `test/` at two short lines; both entries and four comments were
over. Flagged in review by coderabbitai.
* test: cover `__webpack_require__.r` without Symbol support
The `output.environment.symbol: false` branch had no case reaching it: the
one es5 target that looked like it would emits no `__webpack_require__.r`
at all. A CJS `require` of an ESM module reads `__esModule`, which does.
* perf(runtime): use `||=` where `output.environment` allows it
Three assignments wrote the ES5 `x = x || y` form unconditionally instead of
going through `assignOr`, which picks `||=` when
`output.environment.logicalAssignment` is set: the deferred-namespace leaf
prototypes, the `__webpack_require__.O` priority default, and the worklet
bootstrap blob. Output is byte-identical for a target without the flag.
* test: shorten the chunk-url helper comment to two lines
* perf(runtime): drop the unused array branch of `__webpack_require__.d`
The array form of the define-getters helper is emitted by webpack alone, so a
build that emits none cannot receive one and the branch reading it is dead.
Gate it on a new `definePropertyGettersFromArray` tree requirement, requested
where that form is written. The object form stays unconditionally — third-party
code still calls the helper with an object, as its webpack 6 note records.
Also drop the empty string a leading or trailing placeholder leaves in a chunk
filename expression, keeping a quoted operand so the concatenation still yields
a string rather than a bare chunk id.
yarn test:size over test/configCases: -69.10 KiB gzip / -267.61 KiB raw over
854 assets; no runtime that both runs build changed its runtime modules.
* perf(runtime): drop the unreachable trailing-placeholder strip
No chunk filename template in the suite ends with a placeholder while starting
with a literal, so the branch stripping the trailing empty string never ran —
verified by counting its hits over every configCase under both its own config
and the defaults `test:size` builds with. Removing it costs no bytes and
leaves the helper with one branch, both outcomes exercised.
* style: keep the added comments within two lines1 parent ce97d58 commit ff27449
58 files changed
Lines changed: 551 additions & 235 deletions
File tree
- .changeset
- lib
- dependencies
- esm
- runtime
- web
- test
- configCases
- contenthash/hash-placeholders
- html
- inline-script-classic/__snapshots__
- modulepreload-esm/__snapshots__
- script-src-classic/__snapshots__
- script-src-mixed/__snapshots__
- script-src/__snapshots__
- library/modern-module-named-import-externals/__snapshots__
- optimization/static-export-bindings/__snapshots__
- runtime
- define-property-getters-no-value-binding
- __snapshots__
- define-property-getters-value-binding
- __snapshots__
- make-namespace-object-no-symbol
- on-chunks-loaded-priority
- worker/this-in-worker-entry-global-this
- statsCases
- chunk-module-id-range/__snapshots__
- split-chunks-max-size/__snapshots__
- tree-shaking/__snapshots__
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 | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
136 | 141 | | |
137 | 142 | | |
138 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
208 | | - | |
209 | 208 | | |
210 | 209 | | |
211 | 210 | | |
| |||
314 | 313 | | |
315 | 314 | | |
316 | 315 | | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
317 | 326 | | |
318 | 327 | | |
319 | 328 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1291 | 1291 | | |
1292 | 1292 | | |
1293 | 1293 | | |
| 1294 | + | |
| 1295 | + | |
1294 | 1296 | | |
1295 | 1297 | | |
1296 | 1298 | | |
| |||
1324 | 1326 | | |
1325 | 1327 | | |
1326 | 1328 | | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
1327 | 1342 | | |
1328 | 1343 | | |
1329 | 1344 | | |
| |||
1829 | 1844 | | |
1830 | 1845 | | |
1831 | 1846 | | |
1832 | | - | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
1833 | 1851 | | |
1834 | 1852 | | |
1835 | 1853 | | |
1836 | 1854 | | |
1837 | 1855 | | |
1838 | 1856 | | |
1839 | 1857 | | |
1840 | | - | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
1841 | 1862 | | |
1842 | 1863 | | |
1843 | 1864 | | |
| |||
1857 | 1878 | | |
1858 | 1879 | | |
1859 | 1880 | | |
1860 | | - | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
1861 | 1885 | | |
1862 | 1886 | | |
1863 | 1887 | | |
| |||
1883 | 1907 | | |
1884 | 1908 | | |
1885 | 1909 | | |
1886 | | - | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
1887 | 1914 | | |
1888 | 1915 | | |
1889 | 1916 | | |
| |||
1904 | 1931 | | |
1905 | 1932 | | |
1906 | 1933 | | |
1907 | | - | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
1908 | 1938 | | |
1909 | 1939 | | |
1910 | 1940 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
156 | 159 | | |
157 | 160 | | |
158 | 161 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
| 268 | + | |
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
100 | 102 | | |
101 | 103 | | |
102 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
| |||
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
54 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
| 20 | + | |
| 21 | + | |
16 | 22 | | |
17 | 23 | | |
18 | 24 | | |
| |||
33 | 39 | | |
34 | 40 | | |
35 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
36 | 60 | | |
37 | 61 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
49 | 67 | | |
50 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
51 | 79 | | |
52 | 80 | | |
53 | | - | |
54 | | - | |
55 | | - | |
| 81 | + | |
56 | 82 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
78 | 86 | | |
79 | 87 | | |
80 | 88 | | |
| |||
0 commit comments