Skip to content
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

perf(css): improve postcss config resolve #12484

Merged
merged 3 commits into from
Mar 21, 2023
Merged

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Mar 19, 2023

Description

With many parallel CSS file requests (especially with preTransformRequest), each CSS will try to resolve the postcss config because the cache has not been filled. This is slow as we only need one CSS file to resolve it, while others can wait for that one result. Otherwise all CSS files will resolve their own postcss config at once, causing slowness.

On top of that, postcss-load-config takes strangely long to load (2s for me), especially if you don't have a config at all. So we need to reduce calling it.

This PR does the above by caching the promise of the config resolve, instead of it's result.

Additional context

Debugging the slowness in https://github.com/sveltejs/vite-plugin-svelte/tree/main/packages/playground/big


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@bluwy bluwy added feat: css p4-important Violate documented behavior or significantly improves performance (priority) performance Performance related enhancement labels Mar 19, 2023
@stackblitz
Copy link

stackblitz bot commented Mar 19, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Comment on lines -806 to +809
const postcssConfig = await resolvePostcssConfig(config, getCssDialect(lang))
const postcssConfig = await resolvePostcssConfig(config)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dialect option can be removed as it was only separated because sugarss mutates the config to add the sugarss parser. Down the code I've refactored to not mutate the config so we can keep a single cache as before.

@patak-dev
Copy link
Member

This is awesome 🔥

ArnaudBarre
ArnaudBarre previously approved these changes Mar 19, 2023
@patak-dev patak-dev added this to the 4.3 milestone Mar 19, 2023
@patak-dev patak-dev merged commit 58e99b6 into main Mar 21, 2023
@patak-dev patak-dev deleted the postcss-config-resolve branch March 21, 2023 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: css p4-important Violate documented behavior or significantly improves performance (priority) performance Performance related enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants