Skip to content

Conversation

@lencioni
Copy link
Collaborator

I've been timing and profiling ESLint runs at Airbnb and noticed that
react/no-unknown-property is particularly slow for us when using the
"detect" setting for React version.

When running ESLint using TIMING=1 on a directory that contains about
500 files to be linted in it, react/no-unknown-property shows up as
taking about 1700ms.

Looking at the callstacks in the profiler, it seems that when this rule
calls getStandardName for every JSXAttribute here, it will actually do
all of the work to detect the React version every time to determine the
correct set of DOM property names. Since there may be a lot of
JSXAttribute nodes in a codebase, this adds up to quite a bit of work.

By specifying the react version in our ESLint config, the
no-unkown-property rule drops out of the top 10 slowest rules entirely,
with the 10th slowest clocking in at 180ms.

I think it would be a good idea to cache the React version when using
detect instead of looking it up every time.

Fixes #2671

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending change

@ljharb ljharb force-pushed the cache-react-version branch from 93fac86 to c9dfc2d Compare June 15, 2020 21:56
ljharb
ljharb approved these changes Jun 15, 2020
@lencioni lencioni force-pushed the cache-react-version branch from c9dfc2d to b3f7a85 Compare June 15, 2020 21:56
I've been timing and profiling ESLint runs at Airbnb and noticed that
react/no-unknown-property is particularly slow for us when using the
"detect" setting for React version.

When running ESLint using TIMING=1 on a directory that contains about
500 files to be linted in it, react/no-unknown-property shows up as
taking about 1700ms.

Looking at the callstacks in the profiler, it seems that when this rule
calls getStandardName for every JSXAttribute here, it will actually do
all of the work to detect the React version every time to determine the
correct set of DOM property names. Since there may be a lot of
JSXAttribute nodes in a codebase, this adds up to quite a bit of work.

By specifying the react version in our ESLint config, the
no-unkown-property rule drops out of the top 10 slowest rules entirely,
with the 10th slowest clocking in at 180ms.

I think it would be a good idea to cache the React version when using
detect instead of looking it up every time.
@lencioni lencioni force-pushed the cache-react-version branch from b3f7a85 to b8e91a5 Compare June 15, 2020 21:59
@ljharb ljharb merged commit b8e91a5 into master Jun 15, 2020
@ljharb ljharb deleted the cache-react-version branch June 15, 2020 22:08
@alexzherdev
Copy link
Contributor

thanks! going back to the original #1978 it looks like the only thing that stopped me for caching this was testing 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

React version "detect" is slow, particularly for no-unknown-property

4 participants