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

CSS minification warnings cause catastrophic performance #1862

Closed
gluck opened this issue Dec 17, 2021 · 2 comments
Closed

CSS minification warnings cause catastrophic performance #1862

gluck opened this issue Dec 17, 2021 · 2 comments

Comments

@gluck
Copy link

gluck commented Dec 17, 2021

( Initially spotted in vitejs/vite#5833 vitejs/vite#5597 )

  1. If esbuild encounters a @charset rule which is not the first statement, it'll generate 1 warning per rule before that one (which can be a lot).
  2. CSS minification performance gets exponential with the number of warnings (at least for this specific warning)

Combining these 2 makes css minification extremely slow when there's such a case.

Reproduction:

Generate a file like:

.foo0 { color: #ffffff; }
.foo1 { color: #ffffff; }
.....
.foo4999 { color: #ffffff; }
@charset "UTF-8";

And run it through esbuild css minifier (takes 5min+ on my laptop):

$ node -e 'for (i=0;i<5000;i++) console.log(`.foo${i} { color: #ffffff; }`);console.log(`@charset "UTF-8";`);' \
   | esbuild --minify --loader=css

Charting this:
image

Workaround

Removing @charset rule (hence the warnings) will fix the issue (minify is instant).
Note: this rule is injected by postcss during vite css bundling, it's not like I'm trying to break esbuild on purpose 🙈

Version

Tested against 0.14.5
Fun fact, I tried to reproduce in stackblitz (esbuild-wasm@0.13.8) and it generates a single warning (not 5000), hence no issue, but running esbuild@0.13.8 on node still exhibits above/bad behavior 🤷

@evanw evanw closed this as completed in 58a6488 Dec 20, 2021
@evanw
Copy link
Owner

evanw commented Dec 20, 2021

Sorry, this was a typo. There was a missing break in the loop.

@gluck
Copy link
Author

gluck commented Dec 20, 2021

Thanks @evanw I confirm it fixes the build issue I had on vite !

There still seem to be a perf issue related to the number of warnings (as in exponential), which you can trigger on different (repeatable) warnings (e.g. I reproduced with json loader duplicate key warning), but I can't tell if it's worth fixing or not, lmk if you want more details.

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

No branches or pull requests

2 participants