Skip to content

Use different datastructure for MIRI relocations - #50866

Merged
bors merged 6 commits into
rust-lang:masterfrom
michaelwoerister:relocations-in-vec
May 23, 2018
Merged

Use different datastructure for MIRI relocations#50866
bors merged 6 commits into
rust-lang:masterfrom
michaelwoerister:relocations-in-vec

Conversation

@michaelwoerister

Copy link
Copy Markdown
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-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 18, 2018
@michaelwoerister

Copy link
Copy Markdown
MemberAuthor

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

@bors try

@bors

bors commented May 18, 2018

Copy link
Copy Markdown
Collaborator

⌛ 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
Copy Markdown
Contributor

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

@bors

bors commented May 18, 2018

Copy link
Copy Markdown
Collaborator

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

@michaelwoerister

Copy link
Copy Markdown
MemberAuthor

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

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

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@nnethercote

Copy link
Copy Markdown
Contributor

@kennytm

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@michaelwoerister

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
MemberAuthor

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

@kennytm

Copy link
Copy Markdown
Member

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.

@oli-obkoli-obk left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
MemberAuthor

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

comment -> doc comment

@kennytmkennytm 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
Copy Markdown
Contributor

r=me with a rebase

@bors

bors commented May 22, 2018

Copy link
Copy Markdown
Collaborator

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

@michaelwoeristermichaelwoerister changed the title [WIP] Use different datastructure for MIRI relocationsUse different datastructure for MIRI relocationsMay 22, 2018
@michaelwoerister

Copy link
Copy Markdown
MemberAuthor

@bors r=oli-obk

Thanks for the review, @oli-obk!

@bors

bors commented May 22, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit 95fac99 has been approved by oli-obk

@borsbors 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

bors commented May 23, 2018

Copy link
Copy Markdown
Collaborator

⌛ 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

bors commented May 23, 2018

Copy link
Copy Markdown
Collaborator

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

@bors
bors merged commit 95fac99 into rust-lang:masterMay 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
Copy Markdown
Contributor

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
Copy Markdown
MemberAuthor

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
Copy Markdown
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

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: 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

@michaelwoerister@bors@oli-obk@Mark-Simulacrum@ishitatsuyuki@nnethercote@kennytm@eddyb@rust-highfive