Skip to content
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 parsing the root configuration twice #10625

Merged
merged 2 commits into from May 1, 2024

Conversation

MichaReiser
Copy link
Member

Summary

I debugged #10622 and noticed that the root configuration is always resolved twice. This PR changes python_files_in_path to stop searching for configurations if it reached the root-configuration directory (because we can't find any more specific configuration).

Test Plan

I added debug statements to verify that into_settings is no longer called twice for the root configuration.

I see a 4% speedup when running the CPython all cached benchmarks with the default rule selection

hyperfine --warmup 10 --runs 20 \
        "./target/release/ruff-main check crates/ruff_linter/resources/test/cpython -e" \
        "./target/release/ruff check crates/ruff_linter/resources/test/cpython -e"
Benchmark 1: ./target/release/ruff-main check crates/ruff_linter/resources/test/cpython -e
  Time (mean ± σ):      37.1 ms ±   1.1 ms    [User: 43.6 ms, System: 43.6 ms]
  Range (min … max):    35.1 ms …  39.4 ms    20 runs
 
Benchmark 2: ./target/release/ruff check crates/ruff_linter/resources/test/cpython -e
  Time (mean ± σ):      35.3 ms ±   0.7 ms    [User: 36.7 ms, System: 51.0 ms]
  Range (min … max):    34.0 ms …  36.4 ms    20 runs
 
Summary
  ./target/release/ruff check crates/ruff_linter/resources/test/cpython -e ran
    1.05 ± 0.04 times faster than ./target/release/ruff-main check crates/ruff_linter/resources/test/cpython -e

Copy link

github-actions bot commented Mar 27, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@@ -207,6 +207,15 @@ impl RuleSet {
*self = set.union(&RuleSet::from_rule(rule));
}

#[inline]
pub fn set(&mut self, rule: Rule, enabled: bool) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is kind of unrelated but I noticed that we can simplify configuration.rs a bit

Comment on lines +1083 to +1100
let mut rule_selections = config.rule_selections;
rule_selections.extend(self.rule_selections);

let mut extend_safe_fixes = config.extend_safe_fixes;
extend_safe_fixes.extend(self.extend_safe_fixes);

let mut extend_unsafe_fixes = config.extend_unsafe_fixes;
extend_unsafe_fixes.extend(self.extend_unsafe_fixes);

let mut extend_per_file_ignores = config.extend_per_file_ignores;
extend_per_file_ignores.extend(self.extend_per_file_ignores);
Copy link
Member Author

Choose a reason for hiding this comment

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

Another unrelated config change. It avoids allocating a new Vec and instead reuses the existing vector.

@MichaReiser MichaReiser added the internal An internal refactor or improvement label Mar 27, 2024
@MichaReiser MichaReiser force-pushed the avoid-parsing-root-configuration-twice branch from a6331cc to 088771e Compare March 27, 2024 09:50
@MichaReiser MichaReiser force-pushed the avoid-parsing-root-configuration-twice branch from 088771e to 926ac20 Compare May 1, 2024 09:12
@MichaReiser MichaReiser marked this pull request as ready for review May 1, 2024 09:20
@MichaReiser MichaReiser enabled auto-merge (squash) May 1, 2024 09:20
@MichaReiser MichaReiser merged commit 376fb71 into main May 1, 2024
19 checks passed
@MichaReiser MichaReiser deleted the avoid-parsing-root-configuration-twice branch May 1, 2024 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants