eslint-plugin-react: [Bug]: Performance Regression

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

Upgrading from 7.33.1 to 7.33.2 causes a few rules to slow down significantly.

A few rules that appear to have gotten significantly slower are:

  • react/no-array-index-key
  • react/no-unstable-nested-components
  • react/no-danger-with-children

Our overall linting time goes from ~60s to ~90s only changing this one package.

Using eslint timing settings you can see here that these two rules are occupying a good amount of time relative to before the upgrade.

7.33.2:

react/no-array-index-key              | 21522.183 |    30.7%
react/no-unstable-nested-components   |  7283.991 |    10.4%
react/no-danger-with-children         |  2138.971 |     3.0%

7.33.1:

react/no-array-index-key              |   718.943 |     1.8%
react/no-unstable-nested-components   |  1208.373 |     3.0%
react/no-danger-with-children         |  Not slow enough to be in top 10

Pertinent package versions:

Unfortunately I can’t share our codebase and I don’t have a reproduction. Hopefully the code diff between .1 and .2 are small enough to be able to track down this regression.

Expected Behavior

I expect the two versions to be similar in speed.

eslint-plugin-react version

7.33.2

eslint version

8.47.0

node version

18.16.1

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Reactions: 1
  • Comments: 20 (12 by maintainers)

Commits related to this issue

Most upvoted comments

@ljharb the update in https://github.com/ljharb/safe-array-concat/issues/2 fixes the issue.

The change to iterator.prototype either has very little effect but is probably a good change anyway.

Using 7.33.2 and iterator.prototype 1.1.1 it helps a little. Down from ~89s to ~78-80s but still not back down to the ~55-59s range as 7.33.1.

Rule                                  | Time (ms) | Relative
:-------------------------------------|----------:|--------:
react/no-array-index-key              | 17831.444 |    28.9%
redos/no-vulnerable                   | 11373.265 |    18.4%
@typescript-eslint/no-unsafe-argument | 11122.301 |    18.0%
react/no-unstable-nested-components   |  6134.390 |     9.9%
import/no-duplicates                  |  5302.239 |     8.6%
react/no-danger-with-children         |  1932.733 |     3.1%
@typescript-eslint/no-redeclare       |   849.440 |     1.4%
@typescript-eslint/no-unused-vars     |   689.812 |     1.1%
camelcase                             |   562.923 |     0.9%
simple-import-sort/imports            |   428.665 |     0.7%

________________________________________________________
Executed in   80.72 secs    fish           external
   usr time   98.35 secs   33.00 micros   98.35 secs
   sys time    6.36 secs  356.00 micros    6.36 secs

Awesome 😃 I’ll close this then. Thanks for helping me debug!

Thanks, I’ll keep looking for more root causes.

Starting with 7.33.1

  • importing const i = require("iterator.prototype"); in Components.js exhibits no change in run time.
  • importing const map = require('es-iterator-helpers/Iterator.prototype.map'); in Components.js causes the slowdown.

In each case, I only imported, the import was never referenced.

Turns out this is caused by https://npmjs.com/iterator.prototype (which is my own package) - specifically, v8 seems to have a huge deopt when Symbol.toStringTag is added onto %Iterator%.prototype.

I’ll publish a fix to that package, and potentially to es-iterator-helpers as well, at which point I’ll close this.

This is the commit causing the slowdowns: https://github.com/jsx-eslint/eslint-plugin-react/commit/e1dd37f743649bf43726fe102a16bc71062d8687

The es iterator shims clearly aren’t as performant as the built-in array functions.