Remove slow HashSet during miri stack frame creation#49274
Remove slow HashSet during miri stack frame creation#49274bors merged 6 commits intorust-lang:masterfrom
Conversation
michaelwoerister
left a comment
There was a problem hiding this comment.
Looks good to me!
If this is something that is also called for trivial constants, I would suggest adding a fast path for that case, e.g.:
if num_locals == 0 {
vec![]
} else {
// scan blocks and statements
}|
r=me with the optimization implemented (if it makes sense). |
|
Even trivial constants have locals. But you're right, we can add a fast path: Constants and statics don't contain any |
|
@bors r=michaelwoerister |
|
📌 Commit 9fa14e4 has been approved by |
| let local = mir::Local::new(i + 1); | ||
| if !annotated_locals.contains(&local) { | ||
| locals[i] = Some(Value::ByVal(PrimVal::Undef)); | ||
| let mut locals = vec![Some(Value::ByVal(PrimVal::Undef)); num_locals]; |
There was a problem hiding this comment.
The reason we didn't use that is theat we don't actually use the return pointer local at all.
There was a problem hiding this comment.
Fixed, the waste of one space is massively outweighted by the many .index() - 1 calls we had.
There was a problem hiding this comment.
Are you sure? Now you have to allocate something on the heap even if it's never used.
There was a problem hiding this comment.
For truly trivial constants (const FOO: usize = 42;) that is true, but even const FOO: usize = 40 + 2; will create that heap alloc.
I added a fast path for trivial constants
| fn collect_storage_annotations<'mir, 'tcx>(mir: &'mir mir::Mir<'tcx>) -> HashSet<mir::Local> { | ||
| use rustc::mir::StatementKind::*; | ||
|
|
||
| let mut set = HashSet::new(); |
There was a problem hiding this comment.
Would be a good idea to check for Hash{Map,Set} used by miri code: if it needs to be a hash map/set, it should be FxHash{Map,Set} instead.
There was a problem hiding this comment.
Done, found a few in interpret::memory
|
@bors r- |
| self.locals[local.index() - 1] = None; | ||
| let old = self.locals[local]; | ||
| self.locals[local] = None; | ||
| return Ok(old); |
There was a problem hiding this comment.
This is just Ok(self.locals[local].take())
|
@bors r=michaelwoerister,eddyb |
|
📌 Commit f9019ae has been approved by |
…er,eddyb Remove slow HashSet during miri stack frame creation fixes rust-lang#49237 probably has a major impact on rust-lang#48846 r? @michaelwoerister cc @eddyb I know you kept telling me to use vectors instead of hash containers... Now I know why.
…er,eddyb Remove slow HashSet during miri stack frame creation fixes rust-lang#49237 probably has a major impact on rust-lang#48846 r? @michaelwoerister cc @eddyb I know you kept telling me to use vectors instead of hash containers... Now I know why.
…er,eddyb Remove slow HashSet during miri stack frame creation fixes rust-lang#49237 probably has a major impact on rust-lang#48846 r? @michaelwoerister cc @eddyb I know you kept telling me to use vectors instead of hash containers... Now I know why.
fixes #49237
probably has a major impact on #48846
r? @michaelwoerister
cc @eddyb I know you kept telling me to use vectors instead of hash containers... Now I know why.