Skip to content

Improve trailing comma rule performance#9867

Merged
MichaReiser merged 1 commit into
mainfrom
perf-trailing-comma
Feb 6, 2024
Merged

Improve trailing comma rule performance#9867
MichaReiser merged 1 commit into
mainfrom
perf-trailing-comma

Conversation

@MichaReiser
Copy link
Copy Markdown
Member

@MichaReiser MichaReiser commented Feb 6, 2024

Summary

I'm not sure what precisely improves performance but these are the things I did:

  • I removed a lot of the iterator chaining. Before flatten, filter_map, chain, coalesce, tuple_windows. Now it's just filter_map I would have expected that Rust sees through that but maybe it does not.
  • I reordered the TokenType variants to match Tok.... I doubt that this has any impact
  • I changed Token::from from &Spanned to (&Tok, TextRange).
  • I avoid reading context.last() when we already set the context in the branch above

Test Plan

cargo test

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Feb 6, 2024

CodSpeed Performance Report

Merging #9867 will improve performances by 10%

Comparing perf-trailing-comma (f7076c4) with main (daae28e)

Summary

⚡ 10 improvements
✅ 20 untouched benchmarks

Benchmarks breakdown

Benchmark main perf-trailing-comma Change
linter/all-rules[large/dataset.py] 92.5 ms 84 ms +10%
linter/all-rules[unicode/pypinyin.py] 10.8 ms 10.3 ms +5.23%
linter/all-rules[pydantic/types.py] 43.9 ms 40 ms +9.67%
linter/all-rules[numpy/ctypeslib.py] 20.6 ms 19.1 ms +8.13%
linter/all-rules[numpy/globals.py] 2.8 ms 2.7 ms +5.63%
linter/all-with-preview-rules[unicode/pypinyin.py] 11.8 ms 11.3 ms +4.7%
linter/all-with-preview-rules[numpy/globals.py] 3.1 ms 2.9 ms +5.02%
linter/all-with-preview-rules[numpy/ctypeslib.py] 23.3 ms 21.6 ms +7.41%
linter/all-with-preview-rules[large/dataset.py] 105.1 ms 96 ms +9.48%
linter/all-with-preview-rules[pydantic/types.py] 51 ms 47.4 ms +7.77%

@MichaReiser MichaReiser force-pushed the perf-trailing-comma branch 2 times, most recently from 538789c to dee1a37 Compare February 6, 2024 22:42
Copy link
Copy Markdown
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

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

I prefer your changes anyway lol.

@MichaReiser MichaReiser added the performance Potential performance improvement label Feb 6, 2024
@MichaReiser MichaReiser changed the title perf trailing comma Improve trailing comma rule performance Feb 6, 2024
@MichaReiser MichaReiser marked this pull request as ready for review February 6, 2024 23:02
@MichaReiser MichaReiser merged commit fdb5eef into main Feb 6, 2024
@MichaReiser MichaReiser deleted the perf-trailing-comma branch February 6, 2024 23:04
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 6, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

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

Labels

performance Potential performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants