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: avoid side effects resolving in dev and in the optimizer/scanner #12789

Conversation

patak-dev
Copy link
Member

Description

We already had some isBuild checks but they weren't in all the places we resolved side effects. I think we should also avoid resolving side effects during deps optimization (both in the scanner and in esbuild).


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@stackblitz
Copy link

stackblitz bot commented Apr 7, 2023

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

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
@patak-dev
Copy link
Member Author

34b9886 (#12789) implements an idea by @bluwy to avoid resolving more than needed for all plugins used from createResolver.

@patak-dev
Copy link
Member Author

Perf improvements confirmed 🎉
https://github.com/fi3ework/vite-benchmark/actions/runs/4640793203

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

You don't have to make me a co-author, but thanks 🙂 One small nit below and I think this is good!

I also noticed we can push a bit further, for container.resolveId usecases as well like:

const resolved = alreadyResolved ?? (await this.resolveId(url, !!ssr))

(await pluginContainer.resolveId(url, undefined, { ssr }))?.id ??

but we can do this in another PR if you prefer.

packages/vite/src/node/plugins/resolve.ts Outdated Show resolved Hide resolved
packages/vite/src/node/plugins/resolve.ts Outdated Show resolved Hide resolved
@patak-dev
Copy link
Member Author

I also noticed we can push a bit further, for container.resolveId usecases as well like:

const resolved = alreadyResolved ?? (await this.resolveId(url, !!ssr))

(await pluginContainer.resolveId(url, undefined, { ssr }))?.id ??

but we can do this in another PR if you prefer.

Oh, good ones! So, should we switch from an option in the resolve plugin to a new option passed to resolveId? Or both like we do with scan? 🤔
Feel free to commit here, or merge and then we work on this idea on another PR. I can try too later today.

@patak-dev
Copy link
Member Author

@bluwy I tried to use idOnly in the two cases above, but I don't know if the complexity is worth it. Let's merge this one and then we can check in a future PR. The thing is that resolving sideEffects is now already avoided in dev, so these two calls would only affect dev SSR externalize logic IIUC. And at least right now, that won't save any compute (only an extra object). Maybe this will make a difference once we refactor the should externalize logic.

@patak-dev patak-dev merged commit fb904f9 into main Apr 8, 2023
18 checks passed
@patak-dev patak-dev deleted the perf/avoid-module-side-effects-resolving-in-dev-and-optimization branch April 8, 2023 06:24
@bluwy
Copy link
Member

bluwy commented Apr 8, 2023

Sounds good to me. We could probably revisit them again in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants