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

[WIP] Always verify incremental hash #84227

Closed
wants to merge 1 commit into from

Conversation

Aaron1011
Copy link
Member

No description provided.

@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(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 Apr 15, 2021
@Aaron1011
Copy link
Member Author

r? @ghost

@Aaron1011
Copy link
Member Author

@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 Apr 15, 2021
@bors
Copy link
Contributor

bors commented Apr 15, 2021

⌛ Trying commit 4c81dce603dbc5cdfc4bae156fca9ecdda12ae88 with merge f4a231fce8df9e7efa79597690860e9a0b28e97f...

@bors
Copy link
Contributor

bors commented Apr 15, 2021

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

@rust-timer
Copy link
Collaborator

Queued f4a231fce8df9e7efa79597690860e9a0b28e97f with parent 2962e7c, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (f4a231fce8df9e7efa79597690860e9a0b28e97f): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

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

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

jyn514 commented Apr 15, 2021

@Aaron1011 what's the difference between this and #83007 ? Did that PR just miss one of the verify calls?

@Aaron1011
Copy link
Member Author

@jyn514: #83007 was a more minimal version of this, to reduce the performance impact. Based on how many bugs that that PR has already found, I suspect that there might be more bugs lurking in the HashStable impls.

@Aaron1011
Copy link
Member Author

I would really like to be able to land this, but the perf impact is terrible.

I had hoped that switching to HighwayHash would help, but it actually appears to decrease performance: #84229

@Mark-Simulacrum
Copy link
Member

On larger crates the perf impact is only ~5%, so it's not too horrible. I think I'd personally like us to squash known bugs before landing this (e.g., the syn failure), so we're not just accumulating more bugs, but other than that it seems OK.

Is there a possibility we can optimize the incremental verification a bit?

It looks like it does several things:

  • checks if dep node is green - this is a hash table lookup and an array lookup
  • computes the hash - not really optimizable?
  • looks up the old hash - again, this is a hash table lookup and an array lookup

At least the first of these seems.. not necessary? Both of the hash table lookups are also with the same key, I think, so we could optimize out the double hashing there with some manual work.

I don't know if it makes sense to do a perf run which just computes the hash but doesn't actually compare it - maybe wrapping in black box or something - to check if that's where all of the overhead is coming from. It probably is, but even shaving off a few dozen instructions from each call might make a nice difference here?

@Aaron1011
Copy link
Member Author

I think I'd personally like us to squash known bugs before landing this (e.g., the syn failure), so we're not just accumulating more bugs

This change would only reveal existing bugs that were currently going undetected. If you think that this PR might cause additional ICEs, then I would argue that that's a reason to land it sooner - those bugs could be causing miscompilations.

@Mark-Simulacrum
Copy link
Member

Yeah, that's a good point. FWIW I am personally willing to r+ this PR "as-is" (I'd like to see the description updated with some details on why) -- I do think the performance isn't ideal but it's also not that bad in most cases.

@Aaron1011
Copy link
Member Author

@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 Apr 16, 2021
@bors
Copy link
Contributor

bors commented Apr 16, 2021

⌛ Trying commit 2893057d60411eab7a939c81f8c081e3a7c61266 with merge d156ee0e47b013725257045a343c9f0863cae288...

@bors
Copy link
Contributor

bors commented Apr 17, 2021

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

@rust-timer
Copy link
Collaborator

Queued d156ee0e47b013725257045a343c9f0863cae288 with parent b0c818c, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (d156ee0e47b013725257045a343c9f0863cae288): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

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

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

bjorn3 commented Apr 17, 2021

For clap-rs-check incr-patched this slows down death_check by 55x.

@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 Oct 27, 2021
@jyn514
Copy link
Member

jyn514 commented Oct 27, 2021

One alternative to somehow improving the perf is to land this as is but for only one or two nightlies. Then people will use it and report ICEs but it won't be a regression for anyone on stable.

@Mark-Simulacrum
Copy link
Member

Yeah, I'm not a big fan of temporary enabling, though we could try it.

I did have a thought about switching the hash algorithm for this verification (for example, to fxhash) -- in theory, that should still catch many cases of bugs: we won't error on collisions, but I would expect those to be fairly rare. I suspect this is pretty painful to implement though...

I've currently gone for an alternative solution, which is checking only a fraction of the hashes (in expectation, every 256th, though we can alter arbitrarily). This should pretty significantly reduce the cost of verification while still (I think) being deterministic and hopefully catching most bugs over time. We can play with the exact ratio here based on perf results.

@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 Oct 27, 2021
@bors
Copy link
Contributor

bors commented Oct 27, 2021

⌛ Trying commit be102b8eaeecec51aaa4ce688a1b92e19ef714f1 with merge 25fee14d1c50219333de853ad1d11d901c3f9a8e...

@bors
Copy link
Contributor

bors commented Oct 27, 2021

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

@rust-timer
Copy link
Collaborator

Queued 25fee14d1c50219333de853ad1d11d901c3f9a8e with parent 337e156, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (25fee14d1c50219333de853ad1d11d901c3f9a8e): comparison url.

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

  • Small improvement in instruction counts (up to -0.3% on incr-unchanged builds of issue-88862)
  • Moderate regression in instruction counts (up to 1.0% on incr-unchanged builds of clap-rs)

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.

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

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

@bors try @rust-timer queue

Dropped the perf opt from this PR so we can more faithfully evaluate this change, and increased the number of affected hashes to 1/32nd.

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

bors commented Oct 27, 2021

⌛ Trying commit 59dbb8c with merge 97d5f8ae1b0d7436d56cadb5e405aadafc64a86f...

@bors
Copy link
Contributor

bors commented Oct 27, 2021

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

@rust-timer
Copy link
Collaborator

Queued 97d5f8ae1b0d7436d56cadb5e405aadafc64a86f with parent dd757b9, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (97d5f8ae1b0d7436d56cadb5e405aadafc64a86f): comparison url.

Summary: This change led to very large relevant regressions 😿 in compiler performance.

  • Very large regression in instruction counts (up to 6.4% on incr-unchanged builds of coercions)

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.

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

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

Closing in favor of #90361, which just has the same commits I force pushed here but is a fresh PR for fresh discussion.

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 8, 2021
…aelwoerister

Enable verification for 1/32th of queries loaded from disk

This is a limited enabling of incremental verification for query results loaded from disk, which previously did not run without -Zincremental-verify-ich. If enabled for all queries, we see a probably unacceptable hit of ~50% in the worst case, so this pairs back the verification to a more limited set based on the hash key.

Per collected [perf results](rust-lang#84227 (comment)), this is a regression of at most 7% on coercions opt incr-unchanged, and typically less than 0.5% on other benchmarks (largely limited to incr-unchanged). I believe this is acceptable performance to land, and we can either ratchet it up or down fairly easily.

We have no real sense of whether this will lead to a large amount of assertions in the wild, but since those assertions may lead to miscompilations today, it seems potentially warranted. We have a good bit of lead time until the next stable release, though the holiday season will also start soon; we may wish to discuss the timing of enabling this and weigh the desire to prevent (possible) miscompilations against assertions.

cc `@rust-lang/wg-incr-comp`
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. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.