Skip to content

Speed up formatting#153

Merged
thecrypticace merged 12 commits intomainfrom
feat/faster-formatting
May 3, 2023
Merged

Speed up formatting#153
thecrypticace merged 12 commits intomainfrom
feat/faster-formatting

Conversation

@thecrypticace
Copy link
Copy Markdown
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
bronisMateusz pushed a commit to bronisMateusz/prettier-plugin-tailwindcss-drupal that referenced this pull request Apr 16, 2025
* Speed up compatible parser loading

* Speed up config loading

* Cleanup code

* Disable pug plugin printer during tests

* Simplify fixture tests

* Cleanup

* Cleanup

* Extract plugin compat handling into separate file

* Refactor

* Add cross-file config reuse

* Move config loading

* Update changelog
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