-
-
Notifications
You must be signed in to change notification settings - Fork 477
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
Avoid multiple iterations over nodes
and symbols
in linter
#5204
Comments
I like where this is going. I need to think on this for a bit before I give an answer. |
This is not a priority, none of the rules are enabled by default. |
#5201 was an example of fixing a rule which was unnecessarily iterating over symbols. |
cc @mysteryven if you're intrested. |
Is there any progress? I think this is a good idea. 🤔 |
I marked this as good first issue since no one is working on this 😅 |
Let me implement it. 👀 |
Thank you @shulaoda! That'd be great. The ones which iterate over Please keep PRs small so we can review them more easily. 1 PR for the changes to Updating |
This is not going to work. The rules are singletons, immutable by design and cannot contain state. They are shared across threads for all files run in parallel. If we really need state, we need to add the states to context, something like |
Ah I didn't realize that rules were shared across threads. As far as I understand, each rule gets its own |
We seem to be able to close this issue now. |
Various linter rules are implemented as a
Rule::run_once
method which iterates overnodes
orsymbols
.Usually this is because they work in 2 passes. The first pass collects info from the AST/symbols and then the 2nd processes that info.
This results in
nodes
orsymbols
being unnecessarily iterated over multiple times, whenrun
andrun_on_symbol
methods are already provided for doing this.I imagine it'd be faster to:
Rule::run_once_at_end
method which executes afterrun
andrun_on_symbol
have executed on all nodes/symbols.Rule::run
andRule::run_on_symbol
take a&mut self
instead of&self
.self
.nodes
orsymbols
as arun
/run_on_symbol
method.run_once_at_end
.It's iterating over
nodes
repeatedly which would likely have the largest perf impact. But there are so many rules which iterate oversymbols
inrun_once
that it might also be having a noticeable impact in aggregate.Which rules?
Rules which use
run_once
in this way are:Iterating over
nodes
eslint/func_names
eslint/no_this_before_super
import/no_named_as_default_member
jest/no_large_snapshots
jest/prefer_hooks_in_order
jsdoc/require_returns
tree_shaking/no_side_effects_in_initialization
(which does a partial tree traversal)Iterating over
symbols
eslint/no_shadow_restricted_name
jest/consistent_test_it
jest/expect_expect
jest/max_expects
jest/max_nested_describes
jest/no_alias_methods
jest/no_conditional_expect
jest/no_confusing_set_timeout
jest/no_disabled_tests
jest/no_done_callback
collect_possible_jest_call_node
@DonIsaac What do you think?
The text was updated successfully, but these errors were encountered: