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 custom implementation of read_buf in Read for &'a FileDesc #108235

Merged
merged 1 commit into from
Feb 20, 2023

Conversation

tmiasko
Copy link
Contributor

@tmiasko tmiasko commented Feb 19, 2023

This allows to skip an unnecessary buffer initialization.

Fixes #108223.

This allows to skip an unnecessary buffer initialization.
@rustbot
Copy link
Collaborator

rustbot commented Feb 19, 2023

r? @joshtriplett

(rustbot has picked a reviewer for you, use r? to override)

@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 Feb 19, 2023
@rustbot
Copy link
Collaborator

rustbot commented Feb 19, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@the8472
Copy link
Member

the8472 commented Feb 19, 2023

Have you measured this properly? The linked issue only gives a single-shot benchmark that involves process spawning, that seems quite noisy (e.g. numbers vary 10x on the playground).

@tmiasko
Copy link
Contributor Author

tmiasko commented Feb 19, 2023

The problem in #108223 is that Command uses non-blocking IO and read_to_end. The read_to_end was delegating to read_buf which was initializing vec up to its capacity. The information about initialized part is not retained between calls to read_to_end, so the initialization work was repeated each time (the amount of work increases proportionally with vec spare capacity).

The test case is of course racy, but the difference is easy measurable on my system.

@the8472
Copy link
Member

the8472 commented Feb 19, 2023

This solves a real issue and is simple enough. Doing additional optimizations as a followup is fine

@bors r+

@bors
Copy link
Contributor

bors commented Feb 19, 2023

📌 Commit b118569 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 Feb 19, 2023
@bors
Copy link
Contributor

bors commented Feb 20, 2023

⌛ Testing commit b118569 with merge 824f915...

@bors
Copy link
Contributor

bors commented Feb 20, 2023

☀️ Test successful - checks-actions
Approved by: the8472
Pushing 824f915 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 20, 2023
@bors bors merged commit 824f915 into rust-lang:master Feb 20, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 20, 2023
@tmiasko tmiasko deleted the read-buf branch February 20, 2023 07:37
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (824f915): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

std::process::Command::output is unacceptably slow
7 participants