Skip to content

Optimize counting digits in line numbers during error reporting further #82562

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

Merged
merged 1 commit into from
Mar 2, 2021

Conversation

llogiq
Copy link
Contributor

@llogiq llogiq commented Feb 26, 2021

This one-ups #82248 by switching the strategy: Instead of dividing the value by 10 repeatedly, we compare with a limit that we multiply by 10 repeatedly. In my benchmarks, this took between 50% and 25% of the original time. The reasons for being faster are:

  1. While LLVM is able to replace a division by constant with a multiply + shift, a plain multiplication is still faster. However, this doesn't even factor, because
  2. Multiplication, unlike division, is const. We also use a simple for-loop instead of a more complex loop + break, which allows
  3. rustc to const-fold the whole loop, and indeed the assembly output simply shows a series of comparisons.

@rust-highfive
Copy link
Contributor

r? @oli-obk

(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 Feb 26, 2021
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@oli-obk
Copy link
Contributor

oli-obk commented Mar 1, 2021

@bors r+

now if we only had perf tests for failing programs 😆

@bors
Copy link
Collaborator

bors commented Mar 1, 2021

📌 Commit 8abc5fd has been approved by oli-obk

@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 Mar 1, 2021
@bors
Copy link
Collaborator

bors commented Mar 2, 2021

⌛ Testing commit 8abc5fd with merge 35dbef2...

@bors
Copy link
Collaborator

bors commented Mar 2, 2021

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 35dbef2 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 2, 2021
@bors bors merged commit 35dbef2 into rust-lang:master Mar 2, 2021
@rustbot rustbot added this to the 1.52.0 milestone Mar 2, 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.

7 participants