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

wip: collect css information in worker #83

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

literalpie
Copy link
Contributor

Even though this plugin is smarter than using postcss with globs, it's still a pretty significant contributor to Vite slowness (in our large app, it adds 5-10 seconds to the first page load, depending on how big the first page load is)

if there are no transformations being done in the plugin, it could make sense to do the parsing in a seperate worker so that it doesn't slow down the main Vite transformation pipeline.

This just proves out the idea, and isn't ready to be merged or anything. See "TODO" comments for a number of things that would be needed if we decide this is worth doing.

You can see the benefit by running the make-files.sh script, then doing pnpm dev in the playground with/without the "worker" option in the vite plugin.

Even though this plugin is smarter than using postcss with globs, it's still a pretty significant contributor to Vite slowness (in our large app, it adds 5-10 seconds to the first page load, depending on how big the first page load is)

if there are no transformations being done in the plugin, it could make sense to do the parsing in a seperate worker so that it doesn't slow down the main Vite transformation pipeline.

This just proves out the idea, and isn't ready to be merged or anything. See "TODO" comments for a number of things that would be needed if we decide this is worth doing.

You can see the benefit by running the make-files.sh script, then doing `pnpm dev` in the playground with/without the "worker" option in the vite plugin.
Copy link

vercel bot commented Mar 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
pandabox-z5kx ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 3, 2025 1:09pm


let latestCss: string | undefined
// Necessary because when using virtual:pandacss in cases with many files,
// the css may be empty the first time the page is loaded, and HMR doesn't work if the page hasn't loaded yet.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to do more testing here. This might only be necessary the first time css is loaded, or it might not be necessary at all if we keep track of if the worker has anything in progress and await it.

@astahmer
Copy link
Owner

astahmer commented Mar 3, 2025

super interesting!

I'm not sure to follow; how does it behave with a worker ? assuming it takes 5-10s (blocking without a worker); now the vite dev server would start instantly again but then the app would not have any style for 5-10s ?


have you tried generating a .cpuprofile (you can inspect it in https://www.speedscope.app/ or within VSCode) to see where most of the time was spent ? if its anything else than the AST parsing we could maybe improve it

let lastCss: string | undefined

let latestCss: string | undefined
// Necessary because when using virtual:pandacss in cases with many files,
Copy link
Owner

Choose a reason for hiding this comment

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

does that imply that there's no issue when using an actual file ? with options.outfile

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right, I didn't see the issue when testing with outfile. I wish I understood better why it's different

@literalpie
Copy link
Contributor Author

literalpie commented Mar 3, 2025

Compared to a current build that takes 10 seconds today (5s in pandabox, and 5s on other transforms), this change should make it take 5 second. Because the worker is in a different thread, the CSS seems to finish about the same time as other transforms. It's just faster because it's parallel.
If the CSS did take longer, the result would be incomplete styles, updating every 1 second as it processes new stuff.

@literalpie
Copy link
Contributor Author

Based on a profile, most of the work is ts-morph stuff from addSourceFile and parseSourceFile in panda, not anything this plugin does.

@literalpie
Copy link
Contributor Author

Here's the speedscope of the playground app with the many files generated
image
It does look like tranformPanda->extractCvaUsages is doing some processing, which could be saved if we allowed optimizeJs: false (if that value is undefined, we currently default to "auto")

The transform time is similar in our real app, but parseSourceFile and addSourceFile are both about 4 seconds instead of 5s/2s split (and our real app has more non-panda transforms happening)

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.

2 participants