Repository navigation
Replies: 1 comment 1 reply
|
I think this is a solid proposal, and I agree that compile hints should be integrated directly into the chunk generation process rather than handled by a post-build script. One important consideration is ensuring that the hint is only added to chunks that are guaranteed to be loaded during the initial page load. This would help avoid unnecessary compilation overhead for chunks that are not immediately needed. I also think source map offsets, content hashes, and SRI digests should all be generated from the final emitted chunk content to ensure consistency and prevent caching issues. For Turbopack, it would be important to apply the hint before chunk hashing and source map generation, so both bundlers produce consistent results. One question worth exploring is whether shared chunks used by multiple page entries can be identified and hinted without accidentally including chunks that are only needed for dynamic imports. Overall, an opt-in experimental flag makes sense. I would support moving forward with this proposal, provided the implementation includes tests for both Webpack and Turbopack, along with production benchmarks across different applications. |
Uh oh!
There was an error while loading. Please reload this page.
Goals
//# allFunctionsCalledOnLoad, on the client chunks every page runs at startup. Chrome 136+ then compiles their functions on the background thread that streams the script, instead of lazily on the main thread while hydration calls them.Non-Goals
Background
Today the only way is a post-build step. Ours reads
rootMainFilesfrombuild-manifest.jsonandentryJSFilesfrom each page's client reference manifest, prepends the hint to those chunks, then rewrites their digests insubresource-integrity-manifest.jsonand in prerendered HTML. It depends on internal manifest formats, and it can't change the hashed file name, so hinted bytes reuse the URL of unhinted bytes that browsers may hold asimmutable. Chrome and V8 have no flag that does the same for a site.Prior art: cloudflare/vinext#4247 hints the static closure of the browser entries in vinext.
Results on a production App Router site (Next.js 16.4, Turbopack). Same build, hint stripped from chunks by request interception in the "without" runs. Cold load in headless Chromium, 4x CPU throttle, median of 7 runs, ms. TBT here is long tasks after FCP until the main thread is idle after hydration.
LCP moved 920 → 864 on home and 2612 → 2156 on the product page. The
loadevent didn't change.Proposal
An opt-in flag, e.g.
experimental.compileHints: true. When it's set, the build prepends//# allFunctionsCalledOnLoadto the chunks a page needs at first load: the root main files and the evaluated chunk group of each page entry. In Turbopack the hint would be part of chunk code generation, so the content hash, the source map offset and the SRI digest all see the final bytes. Chunks reached only through dynamic imports stay lazy, since V8 advises using the hint sparingly.I'm happy to send a PR once the shape of the option is agreed.
All reactions