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

Upgrade indexmap and use it more #75278

Merged
merged 12 commits into from
Aug 9, 2020
Merged

Upgrade indexmap and use it more #75278

merged 12 commits into from
Aug 9, 2020

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Aug 8, 2020

First this upgrades indexmap to 1.5.1, which is now based on hashbrown::raw::RawTable. This means it shares a lot of the same performance characteristics for insert, lookup, etc., while keeping items in insertion order.

Then across various rustc crates, this replaces a lot of Vec+HashMap pairs with a single IndexMap or IndexSet.

Closes #60608.
r? @eddyb

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 8, 2020
@cuviper
Copy link
Member Author

cuviper commented Aug 8, 2020

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Aug 8, 2020

⌛ Trying commit 0215c595e7312af32d7b0ae700685c003e7daba2 with merge 45cb4ac369e8d420fc735c61f879d661b8fd69ca...

@bors
Copy link
Contributor

bors commented Aug 8, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 45cb4ac369e8d420fc735c61f879d661b8fd69ca (45cb4ac369e8d420fc735c61f879d661b8fd69ca)

@rust-timer
Copy link
Collaborator

Queued 45cb4ac369e8d420fc735c61f879d661b8fd69ca with parent f9c2177, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (45cb4ac369e8d420fc735c61f879d661b8fd69ca): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never

@leonardo-m
Copy link

Is the memory usage lower?

@cuviper
Copy link
Member Author

cuviper commented Aug 8, 2020

FWIW, I purposely separated the commits, so we can easily back any of these out if one proves troublesome.

Is the memory usage lower?

The perf results include max-rss -- looks like a mixed bag.

IndexMap is still basically a Vec+Map internally, but it only stores the keys once, which can help memory.

@Mark-Simulacrum
Copy link
Member

max rss is usually really noisy. But those results look like a plausible small win. Usually we can only tell when looking at graphs with a few commits before/after currently (once things are on master).

@cuviper, did you expect the performance regression here? The PR description sounded like things should be better, but the results look worse (at least instruction counts). I guess we need to get a cachegrind diff going.

@cuviper
Copy link
Member Author

cuviper commented Aug 8, 2020

@Mark-Simulacrum I expected existing uses of indexmap to improve with the new hashbrown-based version, and the new uses to be roughly the same, but with a better abstraction. Compare to a prior test that saw 20% worse switching one part to the old indexmap -- at least that kind of hit isn't here anymore. 🙂

The losses here are mostly in -doc, so that might be something that can be specifically targeted further, perhaps backing something out if it can be isolated. The rest look like mixed ups and downs to me.

@Mark-Simulacrum
Copy link
Member

Local profiling indicates that reverting just the Symbol change fixes most (maybe all) of the regression on token-stream-stress-check, so I've pushed that up now, let's see if the same holds across the board: @bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Aug 9, 2020

⌛ Trying commit 1a552da314d08a32594c3084767c0b7fd2c08b68 with merge c0b91af3cd8f045998932334ba4ed2f40fc547ca...

@bors
Copy link
Contributor

bors commented Aug 9, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: c0b91af3cd8f045998932334ba4ed2f40fc547ca (c0b91af3cd8f045998932334ba4ed2f40fc547ca)

@rust-timer
Copy link
Collaborator

Queued c0b91af3cd8f045998932334ba4ed2f40fc547ca with parent 8bc801b, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (c0b91af3cd8f045998932334ba4ed2f40fc547ca): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never

@cuviper
Copy link
Member Author

cuviper commented Aug 9, 2020

Docs still show ~0.5% increase in instructions across the board, but everything else looks neutral or improved.

Flipping to cpu-cycles, it looks better almost everywhere, even for docs. It's quite plausible that the new hashbrown-based indexmap would have better IPC, with its SIMD lookups and all.

The reverted Symbol might fare better with custom index types -- indexmap-rs/indexmap#147 -- since a Symbol wraps a u32 instead of usize. But even with that, it may be that indexmap's little bit of extra indirection on keys is too harmful for those simple &'static str keys. Anyway, that can be explored in future work if we do land custom index types.

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

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

r=me with comment resolved, and ideally the revert commit squashed in or amended with explanation

TerminatorKind::SwitchInt {
discr: Operand::Copy(place),
switch_ty,
values: options.clone().into(),
values: options.into(),
Copy link
Member

Choose a reason for hiding this comment

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

Hm this looks a bit weird, is there a reason this isn't options.clone()? Did I miss something?

Copy link
Member Author

Choose a reason for hiding this comment

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

The values field is a Cow. So before, we had a local &Vec<u128> that could be cloned and converted, and now we have a map and have to collect its values. I guess we could directly collect a Cow though -- I'll do that.

@cuviper
Copy link
Member Author

cuviper commented Aug 9, 2020

By "revert commit squashed", do you mean to effectively rebase that change out of existence? That's fine with me.

@Mark-Simulacrum
Copy link
Member

Yeah, either rebasing it out of existence or alternatively (maybe better, not sure) leaving it in but editing the message to say why we did so.

@cuviper
Copy link
Member Author

cuviper commented Aug 9, 2020

I think it may go unnoticed in the commit history -- I think I'll cut those out and add a new commit with just a comment that Symbol could use indexmap if performance is resolved.

@cuviper
Copy link
Member Author

cuviper commented Aug 9, 2020

@bors r=Mark-Simulacrum

@bors
Copy link
Contributor

bors commented Aug 9, 2020

📌 Commit ca0b89a has been approved by Mark-Simulacrum

@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 Aug 9, 2020
@bors
Copy link
Contributor

bors commented Aug 9, 2020

⌛ Testing commit ca0b89a with merge 18f3be7...

@bors
Copy link
Contributor

bors commented Aug 9, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: Mark-Simulacrum
Pushing 18f3be7 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 9, 2020
@bors bors merged commit 18f3be7 into rust-lang:master Aug 9, 2020
@cuviper cuviper deleted the indexmap branch August 9, 2020 23:36
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

Use indexmap::Index{Map,Set} in the compiler instead of Vec+reverse map.
8 participants