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

ctfe: limit hashing of big const allocations when interning #98097

Merged
merged 2 commits into from
Jun 17, 2022

Conversation

lqd
Copy link
Member

@lqd lqd commented Jun 14, 2022

Const allocations are only hashed for interning. However, they can be large, making the hashing expensive especially since it uses FxHash: it's better suited to short keys, not potentially big buffers like the actual bytes of allocation and the associated 1/8th sized InitMask.

We can partially hash these fields when they're large, hashing the length, and head and tail of these buffers, to
limit possible collisions while avoiding most of the hashing work.

r? @ghost

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 14, 2022
@lqd
Copy link
Member Author

lqd commented Jun 14, 2022

This should only show up in our benchmarks for the heaviest users of const allocs, that is ctfe-stress-5 which has megabytes of statics. Whereas, say, the biggest we usually see during bootstrapping are a few hundred Ks at most (much like, IIRC, the unicode-related benchmarks have codepoint tables of similar sizes).

@bors try @rust-timer queue

@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 Jun 14, 2022
@bors
Copy link
Contributor

bors commented Jun 14, 2022

⌛ Trying commit 365c2d07e7244a69e74e5e383a1964da68d53b1d with merge ad147c4725df34afea504da0eb637357cb4ff376...

@bors
Copy link
Contributor

bors commented Jun 14, 2022

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

@rust-timer
Copy link
Collaborator

Queued ad147c4725df34afea504da0eb637357cb4ff376 with parent edab34a, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ad147c4725df34afea504da0eb637357cb4ff376): comparison url.

Instruction count

  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
1.0% 1.0% 1
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-5.1% -6.7% 4
All 😿🎉 (primary) N/A N/A 0

Max RSS (memory usage)

Results
  • Primary benchmarks: 😿 relevant regression found
  • Secondary benchmarks: no relevant changes found
mean1 max count2
Regressions 😿
(primary)
2.2% 2.2% 1
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
N/A N/A 0
All 😿🎉 (primary) 2.2% 2.2% 1

Cycles

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-20.1% -20.5% 3
All 😿🎉 (primary) N/A N/A 0

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 may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

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

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot added perf-regression Performance regression. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 14, 2022
@lqd
Copy link
Member Author

lqd commented Jun 15, 2022

Cycles and wall-times are interesting here, and show no regression.

Unexpectedly, the coercions debug incr-full benchmark was instead a tiny win locally for me. Debuginfo is still a problem to reproduce the profile using the CI artifacts, but after stripping, cg can run both (I'd expect that not to matter for program totals ?) and is still a tiny -0.4% change.

(I also wonder if there's some weird cg variance on my machine, running this benchmark with the same toolchain, in debug or incremental many times: I had a big +/- 50M instructions change 😱 a few times. I went back to valgrind 0.19 instead of master just in case, but it's worrying)

I'll try only hashing the buffer's length and head, just to see how it looks on the perfbot.

@lqd
Copy link
Member Author

lqd commented Jun 15, 2022

Here as well, slightly better on coercions, so let's see.

@bors try @rust-timer queue

@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 Jun 15, 2022
@bors
Copy link
Contributor

bors commented Jun 15, 2022

⌛ Trying commit f0fd57ab1611c8143ab286050f04e15de7f0da13 with merge 1757554a03f8b24918b67fa4ecd85da2e6ae8a73...

@bors
Copy link
Contributor

bors commented Jun 15, 2022

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

@rust-timer
Copy link
Collaborator

Queued 1757554a03f8b24918b67fa4ecd85da2e6ae8a73 with parent a4cec97, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1757554a03f8b24918b67fa4ecd85da2e6ae8a73): comparison url.

Instruction count

  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-5.1% -6.7% 4
All 😿🎉 (primary) N/A N/A 0

Max RSS (memory usage)

Results
  • Primary benchmarks: 🎉 relevant improvement found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
3.7% 3.9% 2
Improvements 🎉
(primary)
-2.7% -2.7% 1
Improvements 🎉
(secondary)
-2.3% -2.4% 2
All 😿🎉 (primary) -2.7% -2.7% 1

Cycles

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-19.4% -19.6% 3
All 😿🎉 (primary) N/A N/A 0

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 may lead to changes in compiler perf.

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

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels Jun 15, 2022
@lqd
Copy link
Member Author

lqd commented Jun 15, 2022

Alright.

Do you think this could be interesting @oli-obk ?

@lqd
Copy link
Member Author

lqd commented Jun 16, 2022

Let's do one final test with the previous scheme of hashing both the buffers' head and tail, to see whether the coercions benchmark matches my local results (of not being impacted).

@bors try @rust-timer queue

@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 Jun 16, 2022
@bors
Copy link
Contributor

bors commented Jun 16, 2022

⌛ Trying commit e56ac3aa6ea6f1c4fd1a850640ac864f90924048 with merge 50fec4d723e9ef5d66ef11a543c79e3b678e0087...

@bors
Copy link
Contributor

bors commented Jun 16, 2022

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

@lqd
Copy link
Member Author

lqd commented Jun 16, 2022

So maybe it was indeed noisy. I've reverted everything back to the initial version of this PR then.
In any case, I'll let you decide what we do with this: r? @oli-obk :)

@lqd lqd marked this pull request as ready for review June 16, 2022 15:13
@oli-obk
Copy link
Contributor

oli-obk commented Jun 16, 2022

r=me with constants shared

@lqd lqd force-pushed the const-alloc-hash branch from 365c2d0 to c21bf75 Compare June 16, 2022 17:30
Big const allocations hash a large amount of data for interning:
the whole bytes buffer, and the 1/8th sized initmask, with FxHash.
This hash function is made for shorter keys.

This only hashes the length, and head and tail of these buffers, to
limit possible collisions while avoiding most of the hashing work.
@lqd lqd force-pushed the const-alloc-hash branch from c21bf75 to b1f31f8 Compare June 16, 2022 17:37
@lqd
Copy link
Member Author

lqd commented Jun 16, 2022

Once more, with feeling. Last sanity check.

@bors try @rust-timer queue

@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 Jun 16, 2022
@bors
Copy link
Contributor

bors commented Jun 16, 2022

⌛ Trying commit b1f31f8 with merge cc1038029baebe7680a99427a25885339bbfa7aa...

@bors
Copy link
Contributor

bors commented Jun 16, 2022

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

@rust-timer
Copy link
Collaborator

Queued cc1038029baebe7680a99427a25885339bbfa7aa with parent 6ec3993, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (cc1038029baebe7680a99427a25885339bbfa7aa): comparison url.

Instruction count

  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-5.1% -6.7% 4
All 😿🎉 (primary) N/A N/A 0

Max RSS (memory usage)

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

Cycles

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
2.1% 2.1% 1
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-19.5% -19.6% 3
All 😿🎉 (primary) N/A N/A 0

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 may lead to changes in compiler perf.

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

Footnotes

  1. the arithmetic mean of the percent change 2

  2. number of relevant changes 2

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 16, 2022
@lqd lqd force-pushed the const-alloc-hash branch from 74a91a7 to 61dc080 Compare June 16, 2022 21:07
@lqd
Copy link
Member Author

lqd commented Jun 17, 2022

CI is green. I've adjusted the constants and comments.

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Jun 17, 2022

📌 Commit 61dc080 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 Jun 17, 2022
@bors
Copy link
Contributor

bors commented Jun 17, 2022

⌛ Testing commit 61dc080 with merge 43c47db...

@bors
Copy link
Contributor

bors commented Jun 17, 2022

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 17, 2022
@bors bors merged commit 43c47db into rust-lang:master Jun 17, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 17, 2022
@lqd lqd deleted the const-alloc-hash branch June 17, 2022 17:44
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (43c47db): comparison url.

Instruction count

  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-6.6% -6.6% 3
All 😿🎉 (primary) N/A N/A 0

Max RSS (memory usage)

Results
  • Primary benchmarks: 😿 relevant regression found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
3.1% 3.1% 1
Regressions 😿
(secondary)
1.9% 1.9% 1
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-2.2% -2.2% 1
All 😿🎉 (primary) 3.1% 3.1% 1

Cycles

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-18.9% -19.1% 3
All 😿🎉 (primary) N/A N/A 0

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

@rustbot label: -perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

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-compiler Relevant to the compiler 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