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

Eliminate bunch of copies of error codepath from Utf8LossyChunksIter #91244

Merged
merged 2 commits into from
Nov 30, 2021

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Nov 26, 2021

Using a macro to stamp out 7 identical copies of the nontrivial slicing logic to exit this loop didn't seem like a necessary use of a macro. The early return case can be handled by break without practically any changes to the logic inside the loop.

All this code is from early 2014 (#12062—nearly 8 years ago; pre-1.0) so it's possible there were compiler limitations that forced the macro way at the time.

Confirmed that x.py bench library/alloc --stage 0 --test-args from_utf8_lossy is unaffected on my machine.

Using a macro to stamp out 7 identical copies of the nontrivial slicing
logic to exit this loop didn't seem like a necessary use of a macro. The
early return case can be handled by `break` without practically any
changes to the logic inside the loop.

All this code is from early 2014 (7.5 years old, pre-1.0) so it's
possible there were compiler limitations that forced the macro way at
the time.

Confirmed that `x.py bench library/alloc --stage 0 --test-args from_utf8_lossy`
is unaffected on my machine.
@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 26, 2021
};
self.source = &[];
Some(r)
// SAFETY: `i <= self.source.len()` because it only ever increments by 1
Copy link
Member

Choose a reason for hiding this comment

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

i is incremented up to 3 times in some loop iterations?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's incremented up to 4 times in some loop iterations, but what I meant is: in between every pair of i += 1, we always compare i vs self.source.len(). As soon as an i += 1 puts i out of bounds, then if safe_get(self.source, i) & 192 != TAG_CONT_U8 { break; } will terminate the loop because 0 & 192 != 128.

@Mark-Simulacrum
Copy link
Member

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Nov 29, 2021

📌 Commit c6810a5 has been approved by Mark-Simulacrum

@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 Nov 29, 2021
@bors
Copy link
Contributor

bors commented Nov 30, 2021

⌛ Testing commit c6810a5 with merge 94bec90...

@bors
Copy link
Contributor

bors commented Nov 30, 2021

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing 94bec90 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 30, 2021
@bors bors merged commit 94bec90 into rust-lang:master Nov 30, 2021
@rustbot rustbot added this to the 1.59.0 milestone Nov 30, 2021
@dtolnay dtolnay deleted the lossy branch November 30, 2021 04:16
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (94bec90): comparison url.

Summary: This change led to very large relevant mixed results 🤷 in compiler performance.

  • Small improvement in instruction counts (up to -1.3% on incr-unchanged builds of wg-grammar)
  • Very large regression in instruction counts (up to 6.2% on incr-unchanged builds of inflate)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

@rustbot rustbot added the perf-regression Performance regression. label Nov 30, 2021
@Mark-Simulacrum
Copy link
Member

I suspect regressions are due to rust-lang/rustc-perf#1105, with query verification hard enabled I cannot reproduce them. So going to remove that tag.

@Mark-Simulacrum Mark-Simulacrum removed the perf-regression Performance regression. label Nov 30, 2021
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants