Repository navigation
Commit bf21f16
authored
feat(performance): add broadContexts, largeModules and hotspots hints (#21793)
* feat(performance): add broadContexts hint
A context created without a filter takes whatever the directory holds —
`require.context('./locale')` bundles every file under it, whether or not
anything ever asks for one. The catch-all regExp webpack falls back to is
what identifies that, so a context narrowed by a regExp, include or
exclude is left alone, as is one webpack cannot recognize.
A directory of a handful of files costs little however it is matched, so
only contexts carrying at least twenty modules are reported.
* fix(performance): catch every construction that opens a context
The first cut keyed on the exact filter `require.context` falls back to,
which misses the two constructions that reach a whole directory most
often: `require('./locale/' + name)` and `import(\`./locale/\${name}.js\`)`
both get a pattern webpack derives from the expression, `^./.*\.js$`,
never the catch-all. Any pattern opening with a bare wildcard counts now.
A lazy context was missed twice over — it also keeps each match in a
block of its own, so reading only `dependencies` counted none of them.
* feat(performance): add largeModules hint
Names a module that is at least half of the chunk it sits in, so the
report says which single file the chunk really is rather than that the
chunk is big. 'SizeLimitsPlugin' already covers the absolute side — it
fires per asset over 'maxAssetSize' — and this fires on the share, which
it will do while every asset is still within budget.
What counts as worth naming scales with 'maxAssetSize' rather than being
a fixed number of bytes, so raising the budget raises the floor with it.
Scope hoisting is unwrapped first, or the report would name the module
that absorbed the offender instead of the offender.
* feat(performance): add slowPlugins hint
Charges each plugin the time its own code held the main thread. Wall
time from tap to callback does not answer this: async taps nest, and
summing them over one build came to 2.8x the build itself, with
'EntryPlugin' billed for everything 'make' encloses. Timing only the
synchronous stretch of a tap and subtracting any tap that ran inside it
brings the total under the wall clock and puts the optimisation passes
at the top, where the work actually is.
Interception reaches a tap only if it is registered first, so this taps
'compilation' at a stage before the rest and is wired ahead of the other
performance plugins. Hooks are read through their property descriptors
because the ones kept as aliases are getters that warn when read.
* feat(performance): measure loaders and hooks too, as performance.hotspots
Same measurement, three views. A loader is not a tap, so tap
interception never reached one; 'LoaderRunner' now times a loader's own
run through a sink a context carries, absent unless something asked for
it. Every tap already knew which hook it belonged to, so the same self
time groups by hook as well, and the report carries that as a second
view of the one set of numbers rather than a second ranking.
Loaders and plugins are ranked together because no name is ever both,
so nothing is counted twice. 'slowPlugins' is renamed for what it now
covers.
* fix(performance): report each build's own time, and guard a missing budget
Watching keeps the compiler, and nothing cleared the tally between
builds, so a plugin burning the same 120 ms every rebuild was reported
at 119, 239, then 358 ms — every plugin eventually crosses the
threshold and the figures stop meaning anything. A watch case pins one
build's time now; it reports 389 ms at step one without the fix.
Two more from reading it back. A loader and a plugin kept their run
counts in one map, so a shared name would have merged them; the count
now sits beside the time, per kind. And 'largeModules' read
'maxAssetSize' straight, which is 'NaN' for a plugin built by hand and
no size is ever below that — the floor silently stopped applying.
Snapshots of the whole resolved config and of the CLI flags carry the
three new options.
* test(performance): cover the new hints' ranking, and drop what nothing reaches
Every reported hint list is a ranking, but each case produced one entry, so
no comparator ever ran. Three cases now produce two or three, with equal
sizes so the order is the name tie-break alone.
`largeModules` picked the chunk to name by first arrival, which chunk order
does not fix; it names the first by name instead. The `chunkSize === 0`
guard skipped a loop that was already empty, the `maxAssetSize` fallback
restated a default `defaults.js` always applies, and `interceptAll` guarded
against a hookless object no caller can pass.
The comment on `INTERCEPT_STAGE` gave a reason that is not true: tapable
applies a `register` interceptor to the taps a hook already has, so what
the stage buys is the reset running before anything measures.
* test(performance): isolate the tie counter, and say what hotspots measures
`unused-reexports-tie` counted module evaluations on `global`, which Bun's
worker threads share between test files: the cache suite ran first and left
the count above what the config suite then asserted. The counter now lives
in the bundle.
`hotspots` measures synchronous stretches, so work a loader or tap resumes
after an await is outside it. The message said it was what the loader or
plugin costs, without that limit; it now states it.
The three quiet cases said `expect(1).toBe(1)` or checked only the build.
Nothing reads `compilation.hints`, so a hint pushed there with hints off
went unnoticed; each now asserts that channel is empty.
Also folds the three changesets into the one this pull request gets.
* test(performance): trim the ranked cases' comments and placeholder
* chore: keep the changeset summary under 80 characters1 parent 6597fb5 commit bf21f16
330 files changed
Lines changed: 1877 additions & 6 deletions
File tree
- .changeset
- declarations
- lib
- config
- errors
- loaders
- performance
- schemas
- test
- __snapshots__
- configCases/performance
- broad-contexts-clean
- icons
- locale
- broad-contexts-dynamic-import
- locale
- broad-contexts-error
- locale
- broad-contexts-excluded
- locale
- broad-contexts-expression
- locale
- broad-contexts-no-hints
- locale
- broad-contexts-ranked
- icons
- locale
- broad-contexts-stats
- locale
- broad-contexts
- locale
- hotspots-clean
- hotspots-error
- hotspots-loader
- src
- hotspots-no-hints
- hotspots-ranked
- hotspots-stats
- hotspots-waiting
- hotspots
- large-modules-below-floor
- large-modules-clean
- large-modules-error
- large-modules-no-hints
- large-modules-ranked
- large-modules-stats
- large-modules
- unused-reexports-tie
- watchCases/performance/hotspots-per-build
- 0
- 1
- 2
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 | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3275 | 3275 | | |
3276 | 3276 | | |
3277 | 3277 | | |
| 3278 | + | |
| 3279 | + | |
| 3280 | + | |
| 3281 | + | |
| 3282 | + | |
3278 | 3283 | | |
3279 | 3284 | | |
3280 | 3285 | | |
| |||
3314 | 3319 | | |
3315 | 3320 | | |
3316 | 3321 | | |
| 3322 | + | |
| 3323 | + | |
| 3324 | + | |
| 3325 | + | |
| 3326 | + | |
| 3327 | + | |
| 3328 | + | |
| 3329 | + | |
| 3330 | + | |
| 3331 | + | |
3317 | 3332 | | |
3318 | 3333 | | |
3319 | 3334 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
925 | 925 | | |
926 | 926 | | |
927 | 927 | | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
928 | 934 | | |
929 | 935 | | |
930 | 936 | | |
| |||
959 | 965 | | |
960 | 966 | | |
961 | 967 | | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
962 | 980 | | |
963 | 981 | | |
964 | 982 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2401 | 2401 | | |
2402 | 2402 | | |
2403 | 2403 | | |
| 2404 | + | |
2404 | 2405 | | |
2405 | 2406 | | |
2406 | 2407 | | |
2407 | 2408 | | |
2408 | 2409 | | |
2409 | 2410 | | |
2410 | 2411 | | |
| 2412 | + | |
| 2413 | + | |
2411 | 2414 | | |
2412 | 2415 | | |
2413 | 2416 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
| |||
240 | 244 | | |
241 | 245 | | |
242 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
243 | 251 | | |
244 | 252 | | |
245 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
246 | 258 | | |
247 | 259 | | |
248 | 260 | | |
| |||
427 | 439 | | |
428 | 440 | | |
429 | 441 | | |
| 442 | + | |
430 | 443 | | |
431 | 444 | | |
432 | 445 | | |
| |||
0 commit comments