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

Use with_capacity in rewrite_path #6174

Merged
merged 1 commit into from
May 28, 2024
Merged

Conversation

Noratrieb
Copy link
Member

It not only makes rustfmt faster, but also makes the code nicer imo.

performance:

Summary
  ./build/host/stage2/bin/rustfmt library/std/src/lib.rs --edition 2021 ran
    1.03 ± 0.02 times faster than ../rust3/build/host/stage2/bin/rustfmt library/std/src/lib.rs --edition 2021

Final string lengths when formatting core:

143144 counts
(  1)    23535 (16.4%, 16.4%): 4
(  2)    16138 (11.3%, 27.7%): 3
(  3)    15143 (10.6%, 38.3%): 5
(  4)    13477 ( 9.4%, 47.7%): 6
(  5)     9122 ( 6.4%, 54.1%): 7
(  6)     8715 ( 6.1%, 60.2%): 1
(  7)     6321 ( 4.4%, 64.6%): 8
(  8)     6178 ( 4.3%, 68.9%): 11
(  9)     5826 ( 4.1%, 73.0%): 2
( 10)     5168 ( 3.6%, 76.6%): 9
( 11)     4162 ( 2.9%, 79.5%): 10
( 12)     3555 ( 2.5%, 82.0%): 13
( 13)     3337 ( 2.3%, 84.3%): 14
( 14)     3017 ( 2.1%, 86.4%): 17
( 15)     2875 ( 2.0%, 88.4%): 12
( 16)     2345 ( 1.6%, 90.1%): 15
( 17)     1956 ( 1.4%, 91.4%): 16
( 18)     1946 ( 1.4%, 92.8%): 18
( 19)     1410 ( 1.0%, 93.8%): 19
( 20)     1187 ( 0.8%, 94.6%): 20
( 21)     1045 ( 0.7%, 95.3%): 22
( 22)     1042 ( 0.7%, 96.1%): 21
( 23)      792 ( 0.6%, 96.6%): 23
( 24)      649 ( 0.5%, 97.1%): 24
( 25)      619 ( 0.4%, 97.5%): 27
( 26)      569 ( 0.4%, 97.9%): 28
( 27)      540 ( 0.4%, 98.3%): 26
( 28)      460 ( 0.3%, 98.6%): 25
( 29)      328 ( 0.2%, 98.8%): 29
( 30)      243 ( 0.2%, 99.0%): 31
[...]

I also tried 16 first, with slightly worse performance numbers than 32.

Copy link
Contributor

@ytmimi ytmimi left a comment

Choose a reason for hiding this comment

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

Overall the changes seem pretty straightforward, thanks!

src/types.rs Show resolved Hide resolved
It not only makes rustfmt faster, but also makes the code nicer imo.

performance:
```
Summary
  ./build/host/stage2/bin/rustfmt library/std/src/lib.rs --edition 2021 ran
    1.03 ± 0.02 times faster than ../rust3/build/host/stage2/bin/rustfmt library/std/src/lib.rs --edition 2021
```

Final string lengths when formatting `core`:
```
143144 counts
(  1)    23535 (16.4%, 16.4%): 4
(  2)    16138 (11.3%, 27.7%): 3
(  3)    15143 (10.6%, 38.3%): 5
(  4)    13477 ( 9.4%, 47.7%): 6
(  5)     9122 ( 6.4%, 54.1%): 7
(  6)     8715 ( 6.1%, 60.2%): 1
(  7)     6321 ( 4.4%, 64.6%): 8
(  8)     6178 ( 4.3%, 68.9%): 11
(  9)     5826 ( 4.1%, 73.0%): 2
( 10)     5168 ( 3.6%, 76.6%): 9
( 11)     4162 ( 2.9%, 79.5%): 10
( 12)     3555 ( 2.5%, 82.0%): 13
( 13)     3337 ( 2.3%, 84.3%): 14
( 14)     3017 ( 2.1%, 86.4%): 17
( 15)     2875 ( 2.0%, 88.4%): 12
( 16)     2345 ( 1.6%, 90.1%): 15
( 17)     1956 ( 1.4%, 91.4%): 16
( 18)     1946 ( 1.4%, 92.8%): 18
( 19)     1410 ( 1.0%, 93.8%): 19
( 20)     1187 ( 0.8%, 94.6%): 20
( 21)     1045 ( 0.7%, 95.3%): 22
( 22)     1042 ( 0.7%, 96.1%): 21
( 23)      792 ( 0.6%, 96.6%): 23
( 24)      649 ( 0.5%, 97.1%): 24
( 25)      619 ( 0.4%, 97.5%): 27
( 26)      569 ( 0.4%, 97.9%): 28
( 27)      540 ( 0.4%, 98.3%): 26
( 28)      460 ( 0.3%, 98.6%): 25
( 29)      328 ( 0.2%, 98.8%): 29
( 30)      243 ( 0.2%, 99.0%): 31
[...]
```
@ytmimi ytmimi merged commit 28e43b6 into rust-lang:master May 28, 2024
27 checks passed
@Noratrieb Noratrieb deleted the with-capacity branch May 28, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants