Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use different datastructure for MIRI relocations #50866

Merged
merged 6 commits into from
May 23, 2018

Conversation

michaelwoerister
Copy link
Member

This PR makes relocations in MIRI used a sorted vector instead of a BTreeMap which should make a few common operations more efficient. Let's see if that's true.

r? @oli-obk

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

Before reviewing, let's check if that actually makes things faster.

@bors try

@bors
Copy link
Contributor

bors commented May 18, 2018

⌛ Trying commit 34b4f03 with merge cff7e0f...

bors added a commit that referenced this pull request May 18, 2018
[WIP] Use different datastructure for MIRI relocations

This PR makes relocations in MIRI used a sorted vector instead of a `BTreeMap` which should make a few common operations more efficient. Let's see if that's true.

r? @oli-obk
@oli-obk
Copy link
Contributor

oli-obk commented May 18, 2018

General question: do we have any way of profiling rustc? Like with cachegrind?

@bors
Copy link
Contributor

bors commented May 18, 2018

☀️ Test successful - status-travis
State: approved= try=True

@michaelwoerister
Copy link
Member Author

@Mark-Simulacrum, could I get a perf run for this, please?

@kennytm kennytm added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 18, 2018
@Mark-Simulacrum
Copy link
Member

@oli-obk The perf collector supports local benchmarking with a variety of "profilers" https://github.com/rust-lang-nursery/rustc-perf/tree/master/collector#profiling-local-builds.

Perf for cff7e0f queued.

@ishitatsuyuki
Copy link
Contributor

@oli-obk @nnethercote is using cachegrind for analysing the hot spots.

@nnethercote
Copy link
Contributor

@kennytm
Copy link
Member

kennytm commented May 20, 2018

@kennytm kennytm removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 20, 2018
@nnethercote
Copy link
Contributor

Note that style-servo "clean incremental" builds are highly variable, and so those improvements should be ignored. So it's a slight improvement on coercions and inflate, and a slight regression on clap-rs.

@oli-obk
Copy link
Contributor

oli-obk commented May 20, 2018

This seems like a lot of complexity for slight gains. Not sure if it's worth it?

@michaelwoerister
Copy link
Member Author

This seems like a lot of complexity for slight gains. Not sure if it's worth it?

The complexity is in a general purpose data structures that we might want to use elsewhere too instead of BTreeMap, so I think it's fine.

@michaelwoerister
Copy link
Member Author

I'm not sure how trustworthy the NLL benchmarks are.

@kennytm
Copy link
Member

kennytm commented May 21, 2018

Given that the NLL algorithm is still in development and would be improved from other fronts, I believe we could disregard the minor NLL slowdown.

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

oops, forgot to press the "Submit review" button

use std::mem;
use std::ops::{RangeBounds, Bound, Index, IndexMut};

#[derive(Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Default would probably be a good derive to have here, too

use std::ops::{RangeBounds, Bound, Index, IndexMut};

#[derive(Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
pub struct SortedMap<K: Ord, V> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add some docs explaining the type

}
}

// It is up to the caller to make sure that the elements are sorted by key
Copy link
Contributor

Choose a reason for hiding this comment

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

Make this a doc comment


#[inline]
pub fn insert(&mut self, key: K, mut value: V) -> Option<V> {
let index = self.data.binary_search_by(|&(ref x, _)| x.cmp(&key));
Copy link
Contributor

Choose a reason for hiding this comment

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

use binary_search_by_key (also in the other functions further down)

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we can't copy the key in the general case, we'd have to sort by &K which results in:

let index = self.data.binary_search_by_key(&&key, |&(ref x, _)| x);

I'm not sure that's an improvement. I can wrap the lookup in a helper method though. That should make things nicer.

self.data.iter_mut().map(|&mut (ref mut k, _)| k).for_each(f);
}

// It is up to the caller to make sure that the elements are sorted by key
Copy link
Contributor

Choose a reason for hiding this comment

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

comment -> doc comment

@kennytm kennytm 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-review Status: Awaiting review from the assignee but also interested parties. labels May 21, 2018
@oli-obk
Copy link
Contributor

oli-obk commented May 21, 2018

r=me with a rebase

@bors
Copy link
Contributor

bors commented May 22, 2018

☔ The latest upstream changes (presumably #50520) made this pull request unmergeable. Please resolve the merge conflicts.

@michaelwoerister michaelwoerister changed the title [WIP] Use different datastructure for MIRI relocations Use different datastructure for MIRI relocations May 22, 2018
@michaelwoerister
Copy link
Member Author

@bors r=oli-obk

Thanks for the review, @oli-obk!

@bors
Copy link
Contributor

bors commented May 22, 2018

📌 Commit 95fac99 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 22, 2018
@bors
Copy link
Contributor

bors commented May 23, 2018

⌛ Testing commit 95fac99 with merge 1962a70...

bors added a commit that referenced this pull request May 23, 2018
Use different datastructure for MIRI relocations

This PR makes relocations in MIRI used a sorted vector instead of a `BTreeMap` which should make a few common operations more efficient. Let's see if that's true.

r? @oli-obk
@bors
Copy link
Contributor

bors commented May 23, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: oli-obk
Pushing 1962a70 to master...

@bors bors merged commit 95fac99 into rust-lang:master May 23, 2018
This was referenced May 23, 2018
/// It is up to the caller to make sure that the elements are sorted by key
/// and that there are no duplicates.
#[inline]
pub fn insert_presorted(&mut self, mut elements: Vec<(K, V)>) {
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't this take a SortedMap?

Copy link
Member Author

Choose a reason for hiding this comment

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

It could, yes.

for k in keys {
alloc.relocations.remove(&k);
}
alloc.relocations.remove_range(first ..= last);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is doing what it's supposed to be doing. Writing to the first element of a (&(), &())

00 00 00 00  00 00 00 00
|-----4----||-----5-----|

will result in

00 00 00 00  00 00 00 00
|-----9----|

I have a fix incoming

# for free to join this conversation on GitHub. Already have an account? # 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.

9 participants