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

Causing 99% CPU usage #32

Open
cantiero opened this issue Aug 29, 2017 · 9 comments
Open

Causing 99% CPU usage #32

cantiero opened this issue Aug 29, 2017 · 9 comments

Comments

@cantiero
Copy link

Problem:
When a .ejs file is saved, the CPU usage rises to 99%.

How to reproduce:

  • Create a .ejs file
  • Change something in it and save it

Evidence that this extension has something to do with it: I disabled all the other VSCode extensions and the issue does not happen, enabling only this one causes the problem, enabling any other plugin does not.

Running ps aux | grep 32942 returns:
/Downloads/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper /Downloads/Visual Studio Code.app/Contents/Resources/app/out/bootstrap --type=extensionHost

(being 32942 the PID of a Code Helper task is using 99% of the CPU)

VSCode version: 1.15.1
Extension version: 0.0.14

File is attached.
index.ejs.zip

@DDKnoll
Copy link

DDKnoll commented Nov 13, 2017

Also getting this problem. Its a bit different though:

For some reason, typing inside of the <img onLoad={typehere}/>jsx tag immediately causes my CPU to spike to 100% and freezes the editor for about 5 seconds. Disabling this extension fixes the issue.

auto_rename_max_cpu

VS Code version: 1.18.0
extension version: 0.0.15

@kenisteward
Copy link

This probably has to do with the typing to fast issue. I'd suggest what the guy said and only checking tags when the cursor moves out of the tag encapsulation area ( /, <> for example)

This is just a theory though

@omnilord
Copy link

omnilord commented Feb 20, 2018

Same here. I would argue this has nothing to do with typing too fast as Visual Studio Code would lock up from this issue after a single character. Disabled just this extension and the problem stopped. Disabled all extensions and enabled just Auto Rename Tag and the problem resurfaced.

I was editing a ruby .erb file at the time.

Mac OS 10.11.6, El Capitan
Visual Studio Code version: 1.20.1
Extension version 0.0.15

@KrasavinSerg
Copy link

Same problem with *.svg files.

Mac OS 10.11.6, El Capitan
Visual Studio Code version: 1.23.1

@yegorLitvinov
Copy link

Same problem with .vue files
v0.0.15
VS Code Version: 1.25.1

@jerry1100
Copy link

Was able to reproduce. Here's some sample code:

<path strokeWidth="0" fill="white" transform="translate(-1, -1)" d="M11.3 4.7l1.4 1.4L6.8 12 3.3 8.s6l1.4-1.4 2.1 2z" />

The above example might not freeze your editor (because it's short) but you will see extensionHost hit 100%.

Note: we could change <path /> to <foo /> and it will still behave the same. Also, if we use a closing tag (<path></path>) instead of a self-closing tag, then the issue doesn't appear.

See VSCodeVim/Vim#2003 (comment) for more info.

@jerry1100
Copy link

The issue is with the regex on this line:

let regex = /<(\/?)([a-zA-Z][a-zA-Z0-9-_:.]*)?(?:\s[^\s<>]*?[^\s/<>]+?)*?>/g;

Trying it out with the sample code above results in a timeout:
image

However, changing the tags to <path></path> results in a match (as expected).
image

@jerry1100
Copy link

jerry1100 commented Nov 17, 2018

It seems that the regex execution time grows exponentially with the amount of text in the non-capturing group. Here's a basic example:

<foo className="asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf" />

The more "asdf" groups you add the longer it takes. The inverse is also true; the less "asdf" groups, the faster it runs.

screen shot 2018-11-17 at 12 25 52 pm

Still investigating (I wish my regex skills were better).

Update: going to give up on this for now since I don't really understand the code and I'm busy with other things.

@WhiskeyJack96
Copy link

<(?>(/?))(?>([a-zA-Z][a-zA-Z0-9-_:.])?)(?:\s[^\s\/<>]+?)?>
This Breaks the regular expression into groups that disallow Backtracking and should help remediate the problem

@SimonSiefke SimonSiefke mentioned this issue Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants