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

Specialize Bytes on StdinLock<'_> #120053

Merged
merged 1 commit into from
Jan 26, 2024

Conversation

AldanTanneo
Copy link
Contributor

I noticed recently, while profiling a little project, that I was spending a lot of time reading from stdin (even with locking). I was using the .bytes() iterator adaptor; I figured, since StdinLock is a BufReader internally, it would work just as fast. But this is not the case, as Bytes is only specialized for the raw BufReader, and not the StdinLock/MutexGuard wrapper. Performance improved significantly when I wrapped the lock in a new BufReader, but I was still a bit sore about the double buffer indirection.

This PR attempts to specialize it, by simply calling the already specialized implementation on BufReader.

@rustbot
Copy link
Collaborator

rustbot commented Jan 17, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @m-ou-se (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@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 Jan 17, 2024
@AldanTanneo AldanTanneo changed the title specialize Bytes on StdinLock<'_> Specialize Bytes on StdinLock<'_> Jan 18, 2024
@the8472 the8472 assigned the8472 and unassigned m-ou-se Jan 25, 2024
@the8472
Copy link
Member

the8472 commented Jan 25, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Jan 25, 2024

📌 Commit 1b9a013 has been approved by the8472

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 Jan 25, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 26, 2024
…ytes, r=the8472

Specialize `Bytes` on `StdinLock<'_>`

I noticed recently, while profiling a little project, that I was spending a lot of time reading from stdin (even with locking). I was using the `.bytes()` iterator adaptor; I figured, since `StdinLock` is a `BufReader` internally, it would work just as fast. But this is not the case, as `Bytes` is only specialized for the raw `BufReader`, and not the `StdinLock`/`MutexGuard` wrapper. Performance improved significantly when I wrapped the lock in a new `BufReader`, but I was still a bit sore about the double buffer indirection.

This PR attempts to specialize it, by simply calling the already specialized implementation on `BufReader`.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 26, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#107464 (Add `str::Lines::remainder`)
 - rust-lang#118803 (Add the `min_exhaustive_patterns` feature gate)
 - rust-lang#119466 (Initial implementation of `str::from_raw_parts[_mut]`)
 - rust-lang#120053 (Specialize `Bytes` on `StdinLock<'_>`)
 - rust-lang#120124 (Split assembly tests for ELF and MachO)
 - rust-lang#120204 (Builtin macros effectively have implicit #[collapse_debuginfo(yes)])
 - rust-lang#120322 (Don't manually resolve async closures in `rustc_resolve`)
 - rust-lang#120356 (Fix broken markdown in csky-unknown-linux-gnuabiv2.md)

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

Rollup of 8 pull requests

Successful merges:

 - rust-lang#107464 (Add `str::Lines::remainder`)
 - rust-lang#118803 (Add the `min_exhaustive_patterns` feature gate)
 - rust-lang#119466 (Initial implementation of `str::from_raw_parts[_mut]`)
 - rust-lang#120053 (Specialize `Bytes` on `StdinLock<'_>`)
 - rust-lang#120124 (Split assembly tests for ELF and MachO)
 - rust-lang#120204 (Builtin macros effectively have implicit #[collapse_debuginfo(yes)])
 - rust-lang#120322 (Don't manually resolve async closures in `rustc_resolve`)
 - rust-lang#120356 (Fix broken markdown in csky-unknown-linux-gnuabiv2.md)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit cfa583b into rust-lang:master Jan 26, 2024
11 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 26, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 26, 2024
Rollup merge of rust-lang#120053 - AldanTanneo:specialize-stdinlock-bytes, r=the8472

Specialize `Bytes` on `StdinLock<'_>`

I noticed recently, while profiling a little project, that I was spending a lot of time reading from stdin (even with locking). I was using the `.bytes()` iterator adaptor; I figured, since `StdinLock` is a `BufReader` internally, it would work just as fast. But this is not the case, as `Bytes` is only specialized for the raw `BufReader`, and not the `StdinLock`/`MutexGuard` wrapper. Performance improved significantly when I wrapped the lock in a new `BufReader`, but I was still a bit sore about the double buffer indirection.

This PR attempts to specialize it, by simply calling the already specialized implementation on `BufReader`.
@AldanTanneo AldanTanneo deleted the specialize-stdinlock-bytes branch January 26, 2024 14:42
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