Improve content collection styles and scripts build perf#10959
Merged
Improve content collection styles and scripts build perf#10959
Conversation
🦋 Changeset detectedLatest commit: 0cdf248 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
It was actually a bug. There was an empty module script injected.
Member
|
Oooh that's great, nice work identifying this! I wouldn't be surprised if there were a few other inefficient data structures lurking around this part of the codebase... |
ematipico
approved these changes
May 6, 2024
Tests still fail, but idk why yet
matthewp
approved these changes
May 7, 2024
Member
Author
|
Marked this for 4.8 as I'd like to merged this in a minor together (to be safe) |
sarah11918
approved these changes
May 7, 2024
Member
sarah11918
left a comment
There was a problem hiding this comment.
Looks great, @bluwy , and happy to have content collections improvements! Tiny tweak to the changeset mostly so I didn't have to do any grammar research. 😅 (And, collections plural). Otherwise, approved for docs! 🥳
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Merged
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.
Changes
This PR refactors how we handle propagated styles and scripts in the Rollup
generateBundlephase.Context
A propagated module, e.g.
/Users/.../blog.mdx?astroPropagatedAsset, contains styles and scripts. The styles and scripts are only attached to the head if thatblog.mdxis actually rendered, prevent other content styles and scripts from leaking.Before
The data structure we used to track propagated modules to it styles and scripts is something like this:
This is great because we have information of which top-level pages uses what propagated modules and its styles and scripts. However, (correct me if I'm wrong) I noticed we're not using this information at all.
The only place we consume the information is here, but you can notice that both propagated styles searching and propagated scripts searching do the same logic, so in practice the work done in all places are kinda negated.
After
This PR simplifies and flattens it to:
This way there's only a single "propagated module to styles/scripts" map, each key deduplicated, and we can save the work to figure out which page uses what propagated module, which was very expensive.
This is actually the pattern that Content Collection Cache used, and seems like it's on the right track abstracting this. So this PR also unifies how it's handled with CCC.
Performance
The goal of this refactor is to reduce calls to
getParentModuleInfos, before it took 7.5s, now it takes 0.05s. Seems like making the work O(n^2) to O(n) is quite significant.Testing
Existing tests should pass. I think we have some comprehensive tests around this. I also clicked around the local docs build and all looks good as before.
Docs
Added a changeset because I'm a bit afraid this may break some edge cases.