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

Add benchmarks for impl Debug for str #124551

Merged
merged 1 commit into from
May 10, 2024
Merged

Conversation

Swatinem
Copy link
Contributor

In order to inform future perf improvements and prevent regressions, lets add some benchmarks that stress impl Debug for str.


As I am currently working on improving the perf in #121150, its nice to have these benchmarks.

Writing them, I also saw that escapes are written out one char at a time, even though other parts of the code are already optimizing that via as_str, which I intend to do as well as a followup improvement.

r? @cuviper
☝🏻 as you were also assigned to #121150, CC @the8472 if you want to steal the review :-)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 30, 2024
Comment on lines +22 to +29
assert_eq!(s.len(), 64);
assert_eq!(w.buf, expected);
assert_eq!(w.write_calls, expected_write_calls);
Copy link
Member

@the8472 the8472 Apr 30, 2024

Choose a reason for hiding this comment

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

Generally it's better to separate tests from benchmarks. That makes it easier to rewrite the benchmarks in case the optimizer gets too clever and optimizes things away. And it measures fewer things which should increase the SNR.
Right now this would also be benchmarking string comparison.

I know we have a few benchmarks which mix things, but they're not a good example to follow.

You can still write them in a single #[bench] function by running the asserts outside the benchmark loop.
Or you can declare the test strings as consts so they can be reused between tests and benches.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can still write them in a single #[bench] function by running the asserts outside the benchmark loop.
Or you can declare the test strings as consts so they can be reused between tests and benches.

I first tried to extract those to the tests directory, but then ended up leaving them together inside the #[bench] fn outside of the benchmark loop as you suggested.

IMO it makes sense to co-locate these, as especially counting / optimizing the write calls is done purely for performance reasons.

@Swatinem Swatinem force-pushed the debug-str-bench branch from 1eae922 to c28a62f Compare May 1, 2024 07:49
In order to inform future perf improvements and prevent regressions,
lets add some benchmarks that stress `impl Debug for str`.
@cuviper
Copy link
Member

cuviper commented May 9, 2024

Works for me!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 9, 2024

📌 Commit 5fe296c has been approved by cuviper

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 9, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 10, 2024
Add benchmarks for `impl Debug for str`

In order to inform future perf improvements and prevent regressions, lets add some benchmarks that stress `impl Debug for str`.

---

As I am currently working on improving the perf in rust-lang#121150, its nice to have these benchmarks.

Writing them, I also saw that escapes are written out one char at a time, even though other parts of the code are already optimizing that via `as_str`, which I intend to do as well as a followup improvement.

r? `@cuviper`
☝🏻 as you were also assigned to rust-lang#121150, CC `@the8472` if you want to steal the review :-)
bors added a commit to rust-lang-ci/rust that referenced this pull request May 10, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#124551 (Add benchmarks for `impl Debug for str`)
 - rust-lang#124914 (Remove `#[macro_use] extern crate rustc middle` from numerous crates)
 - rust-lang#124915 (`rustc_target` cleanups)
 - rust-lang#124918 (Eliminate some `FIXME(lcnr)` comments)
 - rust-lang#124927 (opt-dist: use xz2 instead of xz crate)
 - rust-lang#124936 (analyse visitor: build proof tree in probe)
 - rust-lang#124943 (always use `GenericArgsRef`)

Failed merges:

 - rust-lang#124955 (Use fewer origins when creating type variables.)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request May 10, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#124551 (Add benchmarks for `impl Debug for str`)
 - rust-lang#124915 (`rustc_target` cleanups)
 - rust-lang#124918 (Eliminate some `FIXME(lcnr)` comments)
 - rust-lang#124927 (opt-dist: use xz2 instead of xz crate)
 - rust-lang#124936 (analyse visitor: build proof tree in probe)
 - rust-lang#124943 (always use `GenericArgsRef`)
 - rust-lang#124955 (Use fewer origins when creating type variables.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f3f9f0c into rust-lang:master May 10, 2024
6 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 10, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 10, 2024
Rollup merge of rust-lang#124551 - Swatinem:debug-str-bench, r=cuviper

Add benchmarks for `impl Debug for str`

In order to inform future perf improvements and prevent regressions, lets add some benchmarks that stress `impl Debug for str`.

---

As I am currently working on improving the perf in rust-lang#121150, its nice to have these benchmarks.

Writing them, I also saw that escapes are written out one char at a time, even though other parts of the code are already optimizing that via `as_str`, which I intend to do as well as a followup improvement.

r? ``@cuviper``
☝🏻 as you were also assigned to rust-lang#121150, CC ``@the8472`` if you want to steal the review :-)
@Swatinem Swatinem deleted the debug-str-bench branch May 10, 2024 10:17
flip1995 pushed a commit to flip1995/rust that referenced this pull request May 17, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#124551 (Add benchmarks for `impl Debug for str`)
 - rust-lang#124915 (`rustc_target` cleanups)
 - rust-lang#124918 (Eliminate some `FIXME(lcnr)` comments)
 - rust-lang#124927 (opt-dist: use xz2 instead of xz crate)
 - rust-lang#124936 (analyse visitor: build proof tree in probe)
 - rust-lang#124943 (always use `GenericArgsRef`)
 - rust-lang#124955 (Use fewer origins when creating type variables.)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants