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

Remove slow HashSet during miri stack frame creation #49274

Merged
merged 6 commits into from
Mar 24, 2018

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Mar 22, 2018

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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 22, 2018
Copy link
Member

@michaelwoerister michaelwoerister left a comment

Choose a reason for hiding this comment

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

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
}

@michaelwoerister
Copy link
Member

r=me with the optimization implemented (if it makes sense).

@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 22, 2018

Even trivial constants have locals. But you're right, we can add a fast path: Constants and statics don't contain any StorageDead or StorageLive statements, so we don't need to run this loop at all, irrelevant of the complexity of the constant.

@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 22, 2018

@bors r=michaelwoerister

@bors
Copy link
Contributor

bors commented Mar 22, 2018

📌 Commit 9fa14e4 has been approved by michaelwoerister

@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 Mar 22, 2018
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];
Copy link
Member

Choose a reason for hiding this comment

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

Please use IndexVec here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason we didn't use that is theat we don't actually use the return pointer local at all.

Copy link
Contributor Author

@oli-obk oli-obk Mar 23, 2018

Choose a reason for hiding this comment

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

Fixed, the waste of one space is massively outweighted by the many .index() - 1 calls we had.

Copy link
Member

Choose a reason for hiding this comment

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

Are you sure? Now you have to allocate something on the heap even if it's never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

👍

fn collect_storage_annotations<'mir, 'tcx>(mir: &'mir mir::Mir<'tcx>) -> HashSet<mir::Local> {
use rustc::mir::StatementKind::*;

let mut set = HashSet::new();
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, found a few in interpret::memory

@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 22, 2018

@bors r-

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 22, 2018
let old = self.locals[local.index() - 1];
self.locals[local.index() - 1] = None;
let old = self.locals[local];
self.locals[local] = None;
return Ok(old);
Copy link
Member

Choose a reason for hiding this comment

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

This is just Ok(self.locals[local].take())

@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 23, 2018

@bors r=michaelwoerister,eddyb

@bors
Copy link
Contributor

bors commented Mar 23, 2018

📌 Commit f9019ae has been approved by michaelwoerister,eddyb

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 23, 2018
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Mar 23, 2018
…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.
kennytm added a commit to kennytm/rust that referenced this pull request Mar 24, 2018
…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.
kennytm added a commit to kennytm/rust that referenced this pull request Mar 24, 2018
…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.
bors added a commit that referenced this pull request Mar 24, 2018
@bors bors merged commit f9019ae into rust-lang:master Mar 24, 2018
@oli-obk oli-obk deleted the slow_miri branch June 15, 2020 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression of compilation times on the latest nightly (2018-03-20)
5 participants