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
Very slow parsing #186
Comments
Actually, I've narrowed it down to this specific filesize, here is a sample svelte file that will take over % time TIMING=1 eslint --ext .svelte,.js,.ts,.cjs 'src/ssr/Head.svelte'
Rule | Time (ms) | Relative
:------------------------|----------:|--------:
svelte/system | 0.177 | 52.1%
svelte/comment-directive | 0.163 | 47.9%
TIMING=1 eslint --ext .svelte,.js,.ts,.cjs 'src/ssr/Head.svelte' 111.59s user 0.46s system 100% cpu 1:51.91 total Also, I have tested to make sure it is not the svelte parser itself. import fs from 'fs';
import {parse} from 'svelte/compiler';
parse(fs.readFileSync('src/ssr/Head.svelte', 'utf8')); Using this code, it ran and finished instantly. |
Thank you for this issue. import fs from "fs";
import { parse } from "svelte/compiler";
const fixture = fs
.readFileSync("src/ssr/Head.svelte", "utf8")
.replace(/(<style.*?>)([\s\S]*?)(<\/style>)/u, (_, p, c, s) => {
return p + c.replace(/\S/gu, " ") + s;
});
parse(fixture); This parser causes this problem because it parses CSS content by replacing it with whitespace. I will consider a workaround when I have time, but it could be a problem with svelte itself. |
I found a problematic regex in svelte. This regex consumes most of the time it takes. |
I opened a issue in the Svelte repository. |
Nice one! 👍 However, one thing I don't understand is that if I run this code: import fs from 'fs';
import {parse} from 'svelte/compiler';
parse(fs.readFileSync('src/ssr/Head.svelte', 'utf8')); directly using svelte |
Is regex part of import fs from "fs";
import { parse } from "svelte/compiler";
const fixture = fs
.readFileSync("src/ssr/Head.svelte", "utf8")
.replace(/(<style.*?>)([\s\S]*?)(<\/style>)/u, '$1$3');
parse(fixture); |
When we remove the content, we need to recalculate the correct location of the node and token. If we use whitespace, we don't need it. |
@ota-meshi Okay I see, fully understand the problem now.
|
I opened PR in the svelte repository. |
@ota-meshi it seems won't be merged any time soon, can I suggest we replace the style content with null (\0) instead of space? I think that will resolve the issue, what do you think? |
No workaround needed once the PR is merged. I will not spend more time on this issue. |
Or maybe @shirotech can just raise a PR to fix that issue instead on our side? |
Now that the latest version of Svelte has been released, so I close this issue. |
Before You File a Bug Report Please Confirm You Have Done The Following...
(
*.svelte
file linting does not work with the parser alone. You should also use eslint-plugin-svelte with it.)What version of ESLint are you using?
8.19.0
What version of
eslint-plugin-svelte
andsvelte-eslint-parser
are you using?latest
What did you do?
I'm using a very minimal configuration, only extending
plugin:svelte/base
which only contains 2 rules:svelte/comment-directive
andsvelte/system
I've run a benchmark on a substantially large project with hundreds of svelte files.
As you can see, those rules only added
6ms
, but it tookover 140 seconds
to parse these files.What did you expect to happen?
eslint should have finished within
2
secondsWhat actually happened?
eslint finished over
140
secondsLink to Minimal Reproducible Example
Because the project is proprietary, I cannot share it in a reproduction repo. But I'm confident it can be replicable on any large project.
Additional comments
No response
The text was updated successfully, but these errors were encountered: