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 log10 for optimizations #89737

Closed
wants to merge 1 commit into from
Closed

Conversation

wooster0
Copy link
Contributor

@wooster0 wooster0 commented Oct 10, 2021

I think the new integer log10 introduced in #70887 has some great potential to be used for some optimization (and the already existing {f32, f64}::log10 too) regarding integer length counting.

If this is benchmarked and doesn't really result in improvements or even results in regressions, I'd leave this open and wait for #88788 to be merged and then try again, but judging by my own testing, there seem to be some improvements already: https://rust.godbolt.org/z/EexoddGhe

  • Refactor the formatting with buffer thing
  • Optimize impl ToString for u8 and impl ToString for i8 with an extra benchmark run after the other stuff is done
  • I was also thinking about whether it makes sense to add something like count_digits that contains this functionality, and I think it does make sense. Maybe I should open an issue for that? (See https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Adding.20a.20new.20function.20to.20std)
  • Figure out what to put in since = "..."
  • When Use log10 for optimizations #89737 (comment) is resolved, have a more sophisticated float length prediction (or add a FIXME).
  • Note to self: don't forget your private todo list.
  • Add FIXMEs to later change some log10s to things like (-i16::MAX).to_string().len().

For now this is just a draft to see if this does anything.

@rust-highfive
Copy link
Collaborator

r? @joshtriplett

(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 Oct 10, 2021
@wooster0
Copy link
Contributor Author

@bors try @rust-timer queue
r? @ghost

@rust-timer
Copy link
Collaborator

Insufficient permissions to issue commands to rust-timer.

@bors
Copy link
Contributor

bors commented Oct 10, 2021

@r00ster91: 🔑 Insufficient privileges: not in try users

@wooster0
Copy link
Contributor Author

May I have a benchmark run on this? Specifically for this to_string: https://github.com/rust-lang/rust/pull/89737/files#diff-1a13885e89de65916e7e0f9436a79cb2e697e23dcaa1a24e8fb3106d8b89dc7eR2404

library/alloc/src/string.rs Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@wooster0
Copy link
Contributor Author

5: @has check failed
 `XPATH PATTERN` did not match
 // @has foo/primitive.i32.html '//div[@id="impl-ToString"]//h3[@class="code-header in-band"]' 'impl<T> ToString for T'

Same error. As I suspected, the changes done in src/librustdoc/html/sources.rs here are indeed unrelated and it's something else. I'm pretty sure the alloc tests ran and succeeded before this so it's probably not the new to_string implementations for integers either.
It says 'impl<T> ToString for T' in that check which looks very suspicious to me. I think it does some checks that fail when my implementations are there (even though the implementations themselves are correct I think). Does anyone that works on librustdoc have a clue what that failing test could stand for?

@rust-log-analyzer

This comment has been minimized.

@fee1-dead
Copy link
Member

@bors try @rust-timer queue

The floating point ToString implementation is not optimized, but we can see if integers benefit from this optimization. Tests do not need to pass for a benchmark run.

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 10, 2021
@bors
Copy link
Contributor

bors commented Oct 10, 2021

⌛ Trying commit 9df17ffb5c33eb34ffca5b225027c167cdf80ccf with merge ad3bd17c19765c771c75e437c77cc66e4a476095...

@bors
Copy link
Contributor

bors commented Oct 10, 2021

☀️ Try build successful - checks-actions
Build commit: ad3bd17c19765c771c75e437c77cc66e4a476095 (ad3bd17c19765c771c75e437c77cc66e4a476095)

@rust-timer
Copy link
Collaborator

Queued ad3bd17c19765c771c75e437c77cc66e4a476095 with parent 0c87288, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ad3bd17c19765c771c75e437c77cc66e4a476095): comparison url.

Summary: This benchmark run did not return any relevant changes.

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

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 10, 2021
@jyn514
Copy link
Member

jyn514 commented Oct 11, 2021

Does anyone that works on librustdoc have a clue what that failing test could stand for?

Feel free to ping me or another team member in the future - I wouldn't have seen this unless I was idly glancing through PRs.

@jyn514
Copy link
Member

jyn514 commented Oct 11, 2021

@r00ster91 I suspect the new impl-ToString header no longer exists and it's called ToString-1 isntead? I can't find the old ToString implementation for i32, though, I'm not sure why the test passed before.

@wooster0
Copy link
Contributor Author

wooster0 commented Oct 11, 2021

@jyn514

Feel free to ping me or another team member in the future - I wouldn't have seen this unless I was idly glancing through PRs.

Ah, ok, sure!

@r00ster91 I suspect the new impl-ToString header no longer exists and it's called ToString-1 isntead? I can't find the old ToString implementation for i32, though, I'm not sure why the test passed before.

Oh, okay. Maybe that's it. I will try ToString-1 then (did that in e8ddaeb).
Maybe the test passed before because of some weird test caching issue? But I'm like 99% sure there is no such "test cache".
I'm not sure either...

@rust-log-analyzer

This comment has been minimized.

@wooster0
Copy link
Contributor Author

Doesn't look like that fixed it. The additional changes I made in src/test/rustdoc/generic-impl.rs (because I thought it has the same issue) seems to have only made it worse.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Dec 1, 2021

☔ The latest upstream changes (presumably #91275) made this pull request unmergeable. Please resolve the merge conflicts.

@@ -2,4 +2,4 @@

include!("primitive/primitive-generic-impl.rs");

// @has foo/primitive.i32.html '//div[@id="impl-ToString"]//h3[@class="code-header in-band"]' 'impl<T> ToString for T'
// @has foo/primitive.i32.html '//div[@id="ToString-1"]//h3[@class="code-header in-band"]' 'impl<T> ToString for T'
Copy link
Member

Choose a reason for hiding this comment

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

Why did this change? This seems like a bug in this PR.

Copy link
Contributor Author

@wooster0 wooster0 Dec 2, 2021

Choose a reason for hiding this comment

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

See #89737 (comment) and #89737 (comment)

I will resolve the conflicts now and see if it's fixed. I will just remove changes to this file altogether because yeah I shouldn't have to change anything there.

@rust-log-analyzer

This comment has been minimized.

@wooster0 wooster0 force-pushed the uselog10 branch 2 times, most recently from 4c61864 to edae5cd Compare December 2, 2021 15:47
@rust-log-analyzer

This comment has been minimized.

@wooster0
Copy link
Contributor Author

wooster0 commented Dec 2, 2021

Removed the specializations and stuff, those things were probably not worth it anyway.

@wooster0 wooster0 marked this pull request as ready for review December 3, 2021 14:49
@bors
Copy link
Contributor

bors commented Jan 25, 2022

☔ The latest upstream changes (presumably #92353) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC Dylan-DPC added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 19, 2022
@Dylan-DPC
Copy link
Member

@r00ster91 if you can resolve the conflicts we can get this reviewed quickly after that

@wooster0
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 19, 2022
@camelid
Copy link
Member

camelid commented Feb 19, 2022

r? rust-lang/libs

Copy link
Member

@camelid camelid left a comment

Choose a reason for hiding this comment

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

I'll let T-libs review this.

@bors
Copy link
Contributor

bors commented Mar 7, 2022

☔ The latest upstream changes (presumably #94706) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

I am a bit lost in the long comment history above. It seems like people thought this should be faster, but it turned out to be slower when measured, and after a few rounds of code changes there has been no new benchmarking presented after the most recent code change (in which "specializations and stuff" was removed).

What benchmark is the most recent revision of the PR based on?

If it isn't something already checked into the repo, would it be possible to get that benchmark added to either library/core/benches/num or library/core/benches/fmt?

@dtolnay dtolnay added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 18, 2022
@wooster0
Copy link
Contributor Author

It is probably best to just close this because the remaining changes are just macro formatting (which I expect to be automated at some point anyway) and very minor changes that turn / 10 loops into less readable log10s. Maybe LLVM already turns those into some kind of log10s already anyway. I think the point of this PR has been lost so I'll close this but if you believe the macro formatting changes are worth doing right now, you can tell me and I'll make another PR.

@wooster0 wooster0 closed this Mar 19, 2022
@dtolnay
Copy link
Member

dtolnay commented Mar 19, 2022

I would be happy to accept your macro formatting changes in a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

None yet