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

perf(formatter): Improve is_expression_parenthesized performance #5825

Merged
merged 1 commit into from
Jul 18, 2023

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Jul 17, 2023

Summary

This PR improves the performance of is_expression_parenthesized by removing the unnecessary check whether the ( is part of a comment if the token is on the same line as the start character of the expression.
Omitting the check for characters on the same line as the expression start is safe because, if there's a comment, then the expression would be commented out too.

This brings down the formatting time of this large file from 16s to 600ms

Test Plan

cargo test

@MichaReiser
Copy link
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 17, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00     11.0±0.03ms     3.7 MB/sec    1.00     11.0±0.03ms     3.7 MB/sec
formatter/numpy/ctypeslib.py               1.00      2.2±0.00ms     7.5 MB/sec    1.00      2.2±0.00ms     7.5 MB/sec
formatter/numpy/globals.py                 1.00    249.1±0.60µs    11.8 MB/sec    1.00    250.0±0.64µs    11.8 MB/sec
formatter/pydantic/types.py                1.02      4.8±0.01ms     5.3 MB/sec    1.00      4.8±0.03ms     5.4 MB/sec
linter/all-rules/large/dataset.py          1.00     15.8±0.08ms     2.6 MB/sec    1.01     16.0±0.11ms     2.5 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      4.0±0.00ms     4.2 MB/sec    1.02      4.1±0.07ms     4.1 MB/sec
linter/all-rules/numpy/globals.py          1.00    524.0±0.61µs     5.6 MB/sec    1.03    538.9±3.22µs     5.5 MB/sec
linter/all-rules/pydantic/types.py         1.00      7.1±0.01ms     3.6 MB/sec    1.01      7.2±0.04ms     3.6 MB/sec
linter/default-rules/large/dataset.py      1.00      7.9±0.01ms     5.2 MB/sec    1.02      8.0±0.02ms     5.1 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1686.8±3.08µs     9.9 MB/sec    1.05   1775.0±4.67µs     9.4 MB/sec
linter/default-rules/numpy/globals.py      1.00    189.1±7.14µs    15.6 MB/sec    1.08    203.5±0.89µs    14.5 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.5±0.01ms     7.2 MB/sec    1.03      3.6±0.01ms     7.0 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.01     13.0±0.24ms     3.1 MB/sec    1.00     12.9±0.21ms     3.2 MB/sec
formatter/numpy/ctypeslib.py               1.00      2.6±0.05ms     6.5 MB/sec    1.00      2.6±0.04ms     6.5 MB/sec
formatter/numpy/globals.py                 1.00    291.7±9.48µs    10.1 MB/sec    1.02   297.7±14.82µs     9.9 MB/sec
formatter/pydantic/types.py                1.01      5.6±0.13ms     4.5 MB/sec    1.00      5.6±0.10ms     4.6 MB/sec
linter/all-rules/large/dataset.py          1.00     18.6±0.27ms     2.2 MB/sec    1.01     18.8±0.22ms     2.2 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      4.9±0.13ms     3.4 MB/sec    1.00      4.9±0.06ms     3.4 MB/sec
linter/all-rules/numpy/globals.py          1.00   591.1±11.42µs     5.0 MB/sec    1.01    596.5±9.12µs     4.9 MB/sec
linter/all-rules/pydantic/types.py         1.00      8.3±0.10ms     3.1 MB/sec    1.01      8.4±0.20ms     3.0 MB/sec
linter/default-rules/large/dataset.py      1.00      9.6±0.13ms     4.2 MB/sec    1.01      9.7±0.10ms     4.2 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00      2.0±0.03ms     8.3 MB/sec    1.02      2.1±0.03ms     8.1 MB/sec
linter/default-rules/numpy/globals.py      1.00    230.6±5.70µs    12.8 MB/sec    1.05    242.7±4.26µs    12.2 MB/sec
linter/default-rules/pydantic/types.py     1.00      4.3±0.09ms     6.0 MB/sec    1.01      4.3±0.07ms     5.9 MB/sec

Copy link
Member

@konstin konstin left a comment

Choose a reason for hiding this comment

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

🚀

@MichaReiser MichaReiser merged commit 3b32e3a into main Jul 18, 2023
16 checks passed
@MichaReiser MichaReiser deleted the perf-is-expression-parenthesized branch July 18, 2023 13:48
evanrittenhouse pushed a commit to evanrittenhouse/ruff that referenced this pull request Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants