-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Fix slow incremental builds (especially on Windows) #17511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains 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
dc089fc
to
1191f53
Compare
d279760
to
93b9c07
Compare
93b9c07
to
919b07f
Compare
ace59e9
to
60b6d8b
Compare
60b6d8b
to
0622765
Compare
thecrypticace
approved these changes
Apr 3, 2025
What about the case when a new file appears after starting dev server? (for example new vue sfc component) |
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.
Fixes: #16911
Fixes: #17522
When debugging this issue, we noticed that the
resolve_glob()
function fromdetect_sources.rs
was really slow, specifically on Windows. It turns out that we're now computing the list of globs that we use to attach the file system watchers repeatedly on every change instead of doing it only once per compiler setup. This changed with the updates we added to support@source not "…";
in 4.1.More specifically, we noticed that the way we compute these sources is causing a recursive scan through all folders inside your working directory (including
node_modules/
and.git/
). This happens because that logic uses a vanilla file-system walker and not ourignore
crate for this.When we started investigating it, our first reaction was to change both Vite and PostCSS to use the new
normalized_sources
list instead. This is a list of globs to watch that is computed solely on the input sources and does not require any file-system access and it's what we use in the CLI as well. Think of it as being a**/*
rule for the current working-directory in the basic auto-content case.When we made this change, to our surprise, nothing in our existing integration test broke. From memory, though, we remembered that it's important for PostCSS though to not register a blanket watcher for the current working-directory. It took us quite a bit of tinkering until we were able to craft an example that would cause an endless re-render loop with this patch applied. We've now added a new integration test to have this context in the repository for the future but also it meant that we have to go back to creating a "smarter" list of globs for the file system watcher again.
To fix the regressions, this PR now does two things:
node_modules
and.git
, that walk is now much faster. We also made sure that you can still add a custom source rule to point inside anode_modules
folder and it will still pick up changes like you would suggest (e.g. via@source "../node_modules/my-ui-lib";
).The results? This PR fixes slow rebuilds on Windows where rebuilds go from ~2s to ~20ms.
We suspect that this issue is more pronounced on Windows because of a slower file system in general.
Test plan
Tested it on a reproduction with the following results:
Before:
Screen.Recording.2025-04-03.at.16.35.47.mov
After:
Screen.Recording.2025-04-03.at.16.41.25.mov
Zooming in on the times, it looks like this:
But with these changes:
We also tested this on Windows with the following results:
[ci-all]