[13.x] Index Vite manifest chunks by output file - #61017
Draft
atymic wants to merge 1 commit into
Draft
Conversation
Resolving a CSS file back to its manifest entry scanned the whole manifest once per CSS reference, inside the recursive walk over dynamic imports. Build the file -> key index once per render and look chunks up directly. Keeps the first match on a duplicate 'file' value, matching the previous where()/first() behaviour.
|
Thanks for submitting a PR! Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolving a CSS file back to its manifest entry currently scans the whole manifest, once per CSS reference, inside the recursive walk over dynamic imports. Three sites do it, two via
where('file', $css)and one viafirst(fn ($chunk) => $chunk['file'] === $css).Cost is entries × css_refs × imports. On the manifest I hit this on (434 entries, 145 CSS references, an entrypoint declaring 125 dynamic imports) that's roughly 63k comparisons per render, paid on every request that renders
@vite(...). I found it on Lambda where the call was taking ~54ms.This builds the
file->keyindex once per render and looks chunks up directly.The index is a plain local, not a static cache. All of the win comes from reusing it across the ~145 lookups within one render, so persisting it between requests measured no faster and would have meant a second never-cleared static next to
$manifests.chunkKeysByFile()keeps the first match on a duplicatefilevalue, matchingwhere(...)->first().Benchmarks
Real
Illuminate\Foundation\Vite, 430 entry manifest, 30 iterations, median. There's no benchmark suite in the repo so this is a standalone script, happy to share it.Output is unchanged
Rendered HTML plus
preloadedAssets()across 5 entrypoint combinations × 3 prefetch strategies, diffed against a pristine copy of the class: 498,317 bytes, byte identical. The fixture includes a duplicatefilevalue to cover the first-match rule.Two tests added, both passing before and after, there to lock in existing behaviour rather than demonstrate a fix. One asserts tags and preloads for CSS reached through nested imports (the existing
testViteWithNestedCssImportonly covers CSS with no manifest entry of its own, and doesn't check preloads). The other pins the first-match behaviour.