-
Notifications
You must be signed in to change notification settings - Fork 216
bradlc.vscode-tailwindcss-0.10.5 makes CPU go Brrrrrrrr #973
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
Comments
After debugging the extension, I've figured out the source of the issue. It starts with this line: tailwindcss-intellisense/packages/tailwindcss-language-service/src/util/classes.ts Line 34 in b715097
It seems like I was able to make a very minimal reproduction: const text = `tv({
base: "disabled:pointer-events-none disabled:opacity-50",
compoundVariants: [
`
const regex = new RegExp("tv\\((([^()]*|\\([^()]*\\))*)\\)", "dg");
const matches = text.matchAll(regex);
// this will freeze the main thread.
matches.next() While the regex issue is more related to tailwind-variants than tailwindcss itself, I still believe that something should be done in order to prevent high CPU usage. |
This is a huge problem that needs fixing |
The regex is prone to catastrophic backtracking. The only fix is to actually write a different regex. I looked into this months ago: #897 (comment) In JS there is no way to "cancel" a regex once it's started searching. If you sample the process it'll actually be stuck inside V8 itself (the JS engine that powers Node). Node does have worker threads so that might be a way to keep the main thread responsive (and maybe terminate a thread that's stuck) but I actually have no idea if that would work. I'll have to look into it. |
Going to close in favor of #963 given that it's the same problem |
@thecrypticace I ran some tests and while I was unable to In a nutshell: Main Thread -> Timeout Worker -> Regex Worker The timeout worker is responsible for forwarding the messages between the regex worker and the main process, while adding a "kill switch" if the regex worker fails to respond in a given time. |
I am able to |
What version of Tailwind CSS are you using?
3.4.3
What build tool (or framework if it abstracts the build tool) are you using?
postcss 8.4.38
What version of Node.js are you using?
v20.10.0
What browser are you using?
N/A
What operating system are you using?
macOS
Reproduction URL
https://github.com/Newbie012/bug-tailwindcss-cpu
Describe your issue
I have a file with a lot of tailwind classes. Whenever I open it, the tailwind (vscode) extension freezes. You can see in the screenshot 2 processes (it opens a new one without closing the previous process every time I restart vscode) that points to the vscode extension.
Steps to Reproduce
pnpm install
component.ts
Please let me know if I missed any details so I can share it.
Thanks!
The text was updated successfully, but these errors were encountered: