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

cache symbol names in ty::maps #41507

Merged
merged 3 commits into from
Apr 27, 2017
Merged

cache symbol names in ty::maps #41507

merged 3 commits into from
Apr 27, 2017

Conversation

arielb1
Copy link
Contributor

@arielb1 arielb1 commented Apr 24, 2017

this fixes a performance regression introduced in commit 39a58c3.

r? @nikomatsakis

#[derive(Clone)]
pub struct SymbolName {
// FIXME: we don't rely on interning or equality here - better have
// this be a `&'tcx str`.
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by "don't rely on interning or equality here"? Maybe you mean for equality? The main thing to be careful of (which &'tcx str would solve) is that we hash the string contents (if you use Symbol, things go awry).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, that comment was needed because a previous try used Symbol there, which as you said is dangerous. I'll remove it.

@@ -164,7 +154,8 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> {
/// A counter that is used for generating local symbol names
local_gen_sym_counter: Cell<usize>,

symbol_cache: &'a SymbolCache<'a, 'tcx>,
/// A placeholder so we can add lifetimes
placeholder: PhantomData<&'a ()>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just remove 'a? I think I added it in my PR expressly for this field. But whatever, seems fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missed that. Didn't want to cause unnecessary diffs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems fine.

symbol_map.get(TransItem::Fn(instance))
.map(str::to_owned)
.unwrap_or_else(|| symbol_name(instance, tcx))
str::to_owned(&symbol_name(instance, tcx))
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we just replace this entire function with a call to symbol_name (and change return type to InternedString, of course)? It seems like we should remove the secondary caching performed by SymbolMap, and instead have that also use the queries, no?

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

LGTM, but I'm curious what you think about removing the SymbolMap too.

let items: Vec<_> = self.items.iter().map(|(&i, &l)| (i, l)).collect();
let mut items : Vec<_> = items.iter()
.map(|il| (il, item_sort_key(tcx, il.0))).collect();
items.sort_by(|&(_, ref key1), &(_, ref key2)| key1.cmp(key2));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused by this. Aren't there sometimes multiple items with the same node-id that nonetheless deserve a consistent ordering (e.g., different instantiations of the same instance?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. Let me fix that.

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Curious about the sorting thing, otherwise seems good.

for cgu in cgus {
debug!("CodegenUnit {}:", cgu.name);

for (trans_item, linkage) in &cgu.items {
let symbol_name = symbol_cache.get(*trans_item);
let symbol_name = trans_item.symbol_name(tcx);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 to making this a method, the fn was awkward.

@@ -164,7 +154,8 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> {
/// A counter that is used for generating local symbol names
local_gen_sym_counter: Cell<usize>,

symbol_cache: &'a SymbolCache<'a, 'tcx>,
/// A placeholder so we can add lifetimes
placeholder: PhantomData<&'a ()>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems fine.

hasher.finish()
}

pub fn symbol_name<'a, 'tcx>(instance: Instance<'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>)
Copy link
Contributor

Choose a reason for hiding this comment

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

Total nit, but I'd expect tcx to be the first argument. Having this be a method seems even better (didn't you do this elsewhere? Or is that just for TransItem?) But I don't care much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was this way originally. Let me move it all the way to a method on Instance.

@arielb1 arielb1 force-pushed the symbol-cache branch 3 times, most recently from a8c9623 to 1199e3e Compare April 24, 2017 17:50
} else {
ItemSortKey::Remote(item.symbol_name(tcx))
}
}, item.symbol_name(tcx))
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 simpler this way anyhow

@arielb1
Copy link
Contributor Author

arielb1 commented Apr 24, 2017

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Apr 24, 2017

📌 Commit af63f14 has been approved by nikomatsakis

@arielb1
Copy link
Contributor Author

arielb1 commented Apr 24, 2017

Fixed finish micro-opt

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Apr 24, 2017

📌 Commit 07d1233 has been approved by nikomatsakis

@arielb1 arielb1 added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Apr 25, 2017
@bors
Copy link
Contributor

bors commented Apr 26, 2017

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

@arielb1
Copy link
Contributor Author

arielb1 commented Apr 26, 2017

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Apr 26, 2017

📌 Commit 07b16cb has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Apr 27, 2017

⌛ Testing commit 07b16cb with merge aed35b2...

@bors
Copy link
Contributor

bors commented Apr 27, 2017

💔 Test failed - status-appveyor

@aidanhs
Copy link
Member

aidanhs commented Apr 27, 2017

@bors retry

Appveyor network issues https://appveyor.statuspage.io/incidents/06gzq846jl9x

@bors
Copy link
Contributor

bors commented Apr 27, 2017

⌛ Testing commit 07b16cb with merge 4961d72...

bors added a commit that referenced this pull request Apr 27, 2017
cache symbol names in ty::maps

this fixes a performance regression introduced in commit 39a58c3.

r? @nikomatsakis
@bors
Copy link
Contributor

bors commented Apr 27, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 4961d72 to master...

@bors bors merged commit 07b16cb into rust-lang:master Apr 27, 2017
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.

4 participants