Skip to content

Improve performance of loading range suppressions#22428

Closed
amyreese wants to merge 3 commits intomainfrom
amy/suppression-perf
Closed

Improve performance of loading range suppressions#22428
amyreese wants to merge 3 commits intomainfrom
amy/suppression-perf

Conversation

@amyreese
Copy link
Member

@amyreese amyreese commented Jan 7, 2026

WIP, not fully baked, checkpointing progress:

  • creates new block range indexer to track indent/dedent ranges
  • pass indexer to suppression loader
  • new implementation of loading from tokens based on comment ranges and block range index
  • doesn't need to walk tokens forward/backward looking for matching indent scopes
  • has issue with first comment in block preceding the indent token, and block range index not knowing

issue #22087

@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 7, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 7, 2026

CodSpeed Performance Report

Merging this PR will degrade performance by 17.64%

Comparing amy/suppression-perf (c7b528e) with main (f97da18)

Summary

❌ 5 regressed benchmarks
✅ 48 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation linter/all-with-preview-rules[numpy/globals.py] 831.7 µs 914.3 µs -9.04%
Simulation linter/all-with-preview-rules[unicode/pypinyin.py] 2.2 ms 2.7 ms -17.64%
Simulation linter/all-with-preview-rules[numpy/ctypeslib.py] 5.2 ms 5.7 ms -8.8%
Simulation linter/all-with-preview-rules[large/dataset.py] 22.3 ms 23.5 ms -5.14%
Simulation linter/all-with-preview-rules[pydantic/types.py] 10.2 ms 11 ms -7.48%

@amyreese amyreese changed the title improve performance of loading range suppressions Improve performance of loading range suppressions Jan 7, 2026
@amyreese amyreese added the internal An internal refactor or improvement label Jan 7, 2026
@amyreese
Copy link
Member Author

amyreese commented Jan 7, 2026

codspeed not happy 🤪

@MichaReiser
Copy link
Member

codspeed not happy 🤪

dbg statements are performance killers

Comment on lines +29 to +31

/// The ranges of all indent/dedent blocks in the source document.
block_ranges: BlockRanges,
Copy link
Member

Choose a reason for hiding this comment

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

I prefer avoiding adding new state to Indexer because it's state that we can't release until the file has finished checking. That's why we generally prefer re-computing information unless doing so is expensive or has to be repeated in many places (recomputing can often also be cheaper).

Are there cases where the implementation in #21441 (review) falls short, making computing this information ahead of time necessary?

@amyreese amyreese closed this Jan 8, 2026
@amyreese amyreese deleted the amy/suppression-perf branch February 5, 2026 00:44
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.

2 participants