-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Slow parsing when blanks are continuous #7675
Comments
Looks like this might be an issue with catastrophic backtracking, where the regex engine tries to backtrack every single one of those 100k spaces to see if it might match the rest of the regex. So that instead of following all 100k spaces, seeing that they don't match the end of the line (because they have a I can think of a couple ways to work around the catastrophic backtracking in this case. First, if if ('trimEnd' in String.prototype) {
this.template = template.trimEnd();
} else {
this.template = template.replace(/\s+$/, '');
} (Unless Svelte plans to drop IE support entirely, in which case the Another approach might be to use the technique described in https://instanceof.me/post/52245507631/regex-emulate-atomic-grouping-with-lookahead to prevent the regex engine from backtracking. Rewrite the BTW, I traced the origin of the |
We had to work around this issue as well in language tools by inserting non-whitespacs characters at the end of each line to prevent this from slowing down. |
This is a parser issue, so if we can run it on Node.js version 8, the minimum supported version of Node.js, I think it's okay if we can't run it in IE. However, Node.js v8 does not support https://node.green/#ES2019-features-string-trimming |
I agree to use |
We only can use built in functions which are part of the node versions Svelte currently supports |
The performance should be improved in 3.50.0. |
Describe the bug
If there are many consecutive blanks, it will be very slow to parse.
I run the following code and found that it took 9000ms.
Reproduction
https://stackblitz.com/edit/node-4tso3q?file=index.js
npm test
Running the following code that uses the svelte parser takes 9000ms.
However, the code for the following template, which has more characters than before, finishes in 50ms.
I think most of the time for template parses is spent on the next regex.
svelte/src/compiler/parse/index.ts
Line 37 in ccbf10c
Logs
No response
System Info
System: OS: macOS 12.4 CPU: (4) x64 Intel(R) Core(TM) i5-6360U CPU @ 2.00GHz Memory: 50.58 MB / 8.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 18.4.0 - /usr/local/bin/node Yarn: 1.22.11 - /usr/local/bin/yarn npm: 8.12.1 - /usr/local/bin/npm Browsers: Chrome: 103.0.5060.114 Firefox: 79.0 Safari: 15.5 npmPackages: svelte: ^3.46.1 => 3.48.0
Severity
annoyance
The text was updated successfully, but these errors were encountered: