-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Optimize empty provenance range checks. #137704
Conversation
Currently it gets the pointers in the range and checks if the result is empty, but it can be done faster if you combine those two steps.
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…cks, r=<try> Optimize empty provenance range checks. Currently it gets the pointers in the range and checks if the result is empty, but it can be done faster if you combine those two steps. r? `@ghost`
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (9c095f0): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking 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 Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary -2.7%, secondary -3.0%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (secondary -2.9%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 770.531s -> 771.055s (0.07%) |
Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri, @rust-lang/wg-const-eval |
Good perf results for |
Nice. Now I really wanna try representing the bytes and init map together with a single treemap of offset + Box pairs for only the defined bytes |
@bors r+ |
🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened. |
FWIW Miri's support for native calls and FFI relies on our memory representation of the actual data bytes being contiguous, and on pre-allocating that range so that we know its address and can use the same address in Miri's internal "virtual" address space. So making this work in Miri could be a bit more tricky (but it'd be a shame to have only const-eval benefit from such an optimization). That said, we also don't have good benchmarks for this in the test suite. I'd appreciate if, once this lands, you could run the Miri benchmark suite with a rustc before and after this PR to ensure it doesn't have unexpected effects. (We have some nice flags to make comparisons easier: |
@@ -117,7 +132,7 @@ impl<Prov: Provenance> ProvenanceMap<Prov> { | |||
/// limit access to provenance outside of the `Allocation` abstraction. | |||
/// | |||
pub fn range_empty(&self, range: AllocRange, cx: &impl HasDataLayout) -> bool { | |||
self.range_get_ptrs(range, cx).is_empty() && self.range_get_bytes(range).is_empty() | |||
self.range_get_ptrs_is_empty(range, cx) && self.range_get_bytes(range).is_empty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do something similar for checking that the bytewise provenance is empty in this range, couldn't we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but for the benchmarks range_get_bytes
wasn't hot at all, while range_get_ptrs
was very hot, so I didn't bother.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the per-byte provenance is empty most of the time. Still it just seems oddly asymmetric now, making one wonder if there is a reason for the asymmetry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be more precise, it is always empty for CTFE. It will only ever be non-empty in Miri, but even there that should be rather rare.
@bors p=5 (encouraging more rollup-nevers to go through before more rollups) |
☀️ Test successful - checks-actions |
Finished benchmarking commit (daf5985): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResults (secondary 0.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 773.437s -> 773.006s (-0.06%) |
… r=oli-obk interpret/provenance_map: consistently use range_is_empty rust-lang#137704 started using this for per-ptr provenance; let's be consistent and use it also for the per-byte provenance check. Also rename the methods to avoid having both "get" and "is_empty" in the name. r? `@oli-obk`
… r=oli-obk interpret/provenance_map: consistently use range_is_empty rust-lang#137704 started using this for per-ptr provenance; let's be consistent and use it also for the per-byte provenance check. Also rename the methods to avoid having both "get" and "is_empty" in the name. r? ``@oli-obk``
… r=oli-obk interpret/provenance_map: consistently use range_is_empty rust-lang#137704 started using this for per-ptr provenance; let's be consistent and use it also for the per-byte provenance check. Also rename the methods to avoid having both "get" and "is_empty" in the name. r? ```@oli-obk```
… r=oli-obk interpret/provenance_map: consistently use range_is_empty rust-lang#137704 started using this for per-ptr provenance; let's be consistent and use it also for the per-byte provenance check. Also rename the methods to avoid having both "get" and "is_empty" in the name. r? ````@oli-obk````
Rollup merge of rust-lang#137920 - RalfJung:provenance-map-emptiness, r=oli-obk interpret/provenance_map: consistently use range_is_empty rust-lang#137704 started using this for per-ptr provenance; let's be consistent and use it also for the per-byte provenance check. Also rename the methods to avoid having both "get" and "is_empty" in the name. r? ````@oli-obk````
interpret/provenance_map: consistently use range_is_empty rust-lang/rust#137704 started using this for per-ptr provenance; let's be consistent and use it also for the per-byte provenance check. Also rename the methods to avoid having both "get" and "is_empty" in the name. r? ````@oli-obk````
interpret/provenance_map: consistently use range_is_empty rust-lang/rust#137704 started using this for per-ptr provenance; let's be consistent and use it also for the per-byte provenance check. Also rename the methods to avoid having both "get" and "is_empty" in the name. r? ````@oli-obk````
Currently it gets the pointers in the range and checks if the result is empty, but it can be done faster if you combine those two steps.
r? @oli-obk