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

Speed up formatting #153

Merged
merged 12 commits into from May 3, 2023
Merged

Speed up formatting #153

merged 12 commits into from May 3, 2023

Conversation

thecrypticace
Copy link
Contributor

@thecrypticace thecrypticace commented May 3, 2023

The way this plugin works currently is that for every invocation of parse by Prettier we:

  • Load compatible plugins (if available)
  • Locate the Tailwind config
  • Load the config
  • Create a context (if the config hasn't changed)

However, in plugins like Svelte or Vue that handle mixed languages, parse is called for every single JS or TypeScript expression. When there's a lot of them all of the above happens once for every single expression in a Svelte or Vue file 😱. Doing this once or twice total isn't a big deal — but if your file has hundreds of expressions, dynamic attributes, etc… this time adds up.

With this change we now do this at most once per source file per 5s interval (this is subject to change). The time interval lets us handle changes to the Tailwind CSS config without performing expensive operations like object hashing while also caching the config and everything associated with it.

When plugins are involved the time and memory savings can be fairly significant. I've seen the time drop from 15s to 3.5s for a Svelte file with 1,000 expressions (around 3s of that is the baseline with just the Svelte plugin). The memory savings in that case dropped from 3.5GB across 3 files to around 350-ish MB.

Fixes #148

This might also fix the issues people have seen in Vue and Next projects but not yet 100% certain.

@thecrypticace thecrypticace merged commit 474c344 into main May 3, 2023
@thecrypticace thecrypticace deleted the feat/faster-formatting branch May 3, 2023 14:33
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.

v0.2.6 completely breaks Prettier in Svelte Projects
1 participant