`eslint-plugin-sonarjs` performance issues on large codebase

Hi

First, apologies if this isn’t the correct place to start a thread like this, but none of the other categories seemed to match either (and this gets the most traffic it seems).

I’m currently in the process of migrating our rather large (~1600 files, 285k LOC according to tokei) codebase to ESLint v9. We’re currently running v7 which includes an older version of eslint-plugin-sonarjs.

We’ve been using both the library and the plugin without issue, performance hasn’t been great but it’s been manageable - especially with caching.

However, as I’ve gone through the process of updating the libraries and plugins to their latest versions, I’ve seen a noticeable drop in performance and, from what I can tell, most of it stems from eslint-plugin-sonarjs.

Without including the plugin in the config, I can run a cold-start (no cache) eslint src on our codebase in about 25s - with the main cause of slowness (according to TIMING=1) being prettier/prettier - which is fine for us.

However, adding sonarJSPlugin.configs.recommended to our config bumps the linting time up to nearly 100s. This is basically a 4x increase from adding the plugin alone. At this point, it’s worth noting that this is already with the sonarjs/no-commented-code rule disabled as I’ve found that to be extremely slow (to the point where ESLint looked like it was never going to complete!).

I’m not sure how much support the plugin is getting at this point, but it would be really cool to have a config that is a subset of the rules that don’t have massive performance penalties. I’ve found at least two are just wrappers on top of TS which feels like wasted work.

If anyone has a similar experience or was around this, it would be great to hear about this. I don’t really want to have to remove the plugin completely, but if the performance penalty keeps going up we might have to!

Cheers

1 Like

Hello @scallaway,

thanks for the feedback. Can you please share the whole output of the ESLint rule performance (using TIMING=1). We are already aware of no-commented-code, and you did the correct quick win disabling it. We are not aware of the other rules being huge offenders in terms of performance, so I would like to see that list if possible.

I understand you are using the latest eslint-plugin-sonarjs version, is that right?

Cheers,
Victor

Hello,
I just ran into the same problem like OP. I’m having a 600 line test file. When using the fix flag it is even worse.

P.S. I’m a bit disappointed that you were not able to fix this in 10 month….

I’m using
“eslint”: “^9.39.2”,
“eslint-plugin-sonarjs”: “^3.0.6”,

TIMING=1 npx eslint .

Rule Time (ms) Relative
sonarjs/no-commented-code 704.906 34.6%
sonarjs/deprecation 323.434 15.9%
prettier/prettier 268.797 13.2%
react-hooks/static-components 250.217 12.3%
sonarjs/aws-restricted-ip-admin-access 152.054 7.5%
import/no-duplicates 49.152 2.4%
sonarjs/assertions-in-tests 19.480 1.0%
react-hooks/rules-of-hooks 13.031 0.6%
sonarjs/no-dead-store 11.355 0.6%
react/no-direct-mutation-state 10.620 0.5%

TIMING=1 npx eslint . –fix

Rule Time (ms) Relative
sonarjs/no-commented-code 12967.341 90.3%
sonarjs/deprecation 327.032 2.3%
prettier/prettier 292.927 2.0%
react-hooks/static-components 244.499 1.7%
sonarjs/aws-restricted-ip-admin-access 157.878 1.1%
import/no-duplicates 60.562 0.4%
sonarjs/assertions-in-tests 20.946 0.1%
react-hooks/rules-of-hooks 14.104 0.1%
sonarjs/no-dead-store 12.851 0.1%
react/no-direct-mutation-state 12.028 0.1%

Hello @Sepp_Mayer @scallaway,

we just released 3.0.7 which contains improvements for that rule. Can you please try and let us know if you see any impact?

Cheers,
Victor

1 Like