Repository navigation
Conversation
esbuild-sass-plugin starts a Dart Sass process in every esbuild build that
includes it, and wp-build adds two instances to each transpile, route and
widget build plus one to each style entry point. A full Gutenberg build
started 722 Dart Sass processes, up to 169 at once.
Replace it with a small plugin that compiles through one sass-embedded
AsyncCompiler, started on first use and disposed after a one-off build.
Watch mode keeps it for later rebuilds. Plain CSS files are still read
as they are, without Sass.
The build output is byte-identical (22,528 files under build/ and
packages/*/build{,-module,-style,-wp}).
Sets `if: false` on every job of the workflows that run on pull_request, except the detect-relevant-changes and build jobs of end2end-test.yml, so only the E2E Build job runs while its time is measured. Drop this commit before merging.
|
Build job timings on
Runner speed varies more than this change. Phase 2 compiles no Sass, so its time indicates the runner: over the 40 most recent upstream jobs it took 18.7–23.9 s on 18 and 26.7–31.0 s on 22. Two of this PR's runs fell in the first group and one in the second. Grouped that way:
As a fraction of Phase 2 in the same job, Phase 1 took 0.93 (0.88–0.99) upstream and 0.78 (0.75–0.78) here; Phases 3 and 4 together took 0.78 (0.73–0.82) upstream and 0.75 (0.74–0.77) here. The gain is in Phase 1, about 4–5 s; Phases 3 and 4 gain about 1–2 s. The Build job total also includes the dependency install (24–72 s in these three runs) and the artifact upload, which vary more than the build does. Local, macOS arm64, three
The machine was running other work, so the local totals do not separate. The tree's RSS rises to 6–7 GB during Phase 2, which compiles no Sass. For comparison, the pure JS |
What?
wp-buildnow compiles Sass through one Dart Sass process for the whole run, instead of starting two in every esbuild build that handles styles.Why?
esbuild-sass-pluginwithembedded: truecallssass-embedded'sinitAsyncCompiler()in each pluginsetup(), so everyesbuild.build()that includes the plugin starts a Dart Sass process and stops it when the build ends.wp-buildadds two plugin instances to each transpile (CJS and ESM), route and widget build, and one to each style entry point, including builds of packages that have no styles.A full
npm run buildon trunk starts 722 Dart Sass processes, up to 169 at once (counted by logging every spawn). Phase 3 runs 56 at once, four for each route with a content bundle, while the process tree's memory use is at its highest in local samples. On macOS arm64 the Dart Sass processes reached 864 MB RSS together in 1-second samples; with this change the single process peaks at 89 MB.How?
lib/sass-plugin.mjsis a small esbuild plugin over oneAsyncCompiler, started on the first Sass file.AsyncCompilerruns concurrent compilations over one process. The plugin callscompileAsync()with the existingimportersandloadPaths, reads.cssfiles as they are without Sass, asesbuild-sass-plugindid, and passes the CSS to the existingtransformcallbacks.main()disposes the compiler after a one-off build, because its child process would otherwise keep Node.js running. Watch mode keeps it for rebuilds.esbuild-sass-plugindependency is removed.Compatibility: imports now resolve by Sass's own rules (relative to the importing file, then
loadPaths, andpkg:URLs throughNodePackageImporter).esbuild-sass-pluginhad its own resolver, which also accepted webpack-style~package/pathimports; those no longer resolve. Gutenberg has none. Sass warnings are printed by Sass instead of being reported as esbuild warnings; the build has none today.The output of
npm run buildis byte-identical to trunk:diff -rofbuild/andpackages/*/build,build-module,build-styleandbuild-wp(22,528 files) reports no difference.The
DROPME:commit disables every CI job except the E2E Build job, so its time can be compared with recent runs. It is for measurement only and will be dropped before merge. Timings will follow in a comment.Testing Instructions
npm run buildon trunk and on this branch, and comparebuild/andpackages/*/build*withdiff -r. They are identical.pgrep -f 'sass.snapshot --embedded' | wc -lshows at most 1.npm run dev, change a declaration inpackages/block-library/src/paragraph/style.scss, and check thatpackages/block-library/build-style/paragraph/style.cssis rebuilt with it. Stop with Ctrl+C; nosass.snapshot --embeddedprocess remains.npm run test:unit -- packages/wp-build/lib/test/sass-plugin.js.Testing Instructions for Keyboard
Not applicable: no UI change.
Use of AI Tools
AI assistance: Yes
Tools: Claude Code
Model: Claude Opus 5.5
Used for: Implementation, tests, measurements and this description.