rustc: Move to FNV hashing for node/def ids

This leverages the new hashing framework and hashmap implementation to provide a
much speedier hashing algorithm for node ids and def ids. The hash algorithm
used is currentl FNV hashing, but it's quite easy to swap out.

I originally implemented hashing as the identity function, but this actually
ended up in slowing down rustc compiling libstd from 8s to 13s. I would suspect
that this is a result of a large number of collisions.

With FNV hashing, we get these timings (compiling with --no-trans, in seconds):

|           |  before  |  after  |
|-----------|---------:|--------:|
| libstd    |   8.324  |  6.703  |
| stdtest   |  47.674  | 46.857  |
| libsyntax |   9.918  |  8.400  |
This commit is contained in:
Alex Crichton
2014-02-28 14:34:26 -08:00
parent 0e95b086db
commit bec7b766fb
27 changed files with 364 additions and 195 deletions

View File

@@ -46,6 +46,7 @@ use serialize::json::ToJson;
use syntax::ast;
use syntax::attr;
use syntax::parse::token::InternedString;
use rustc::util::nodemap::NodeSet;
use clean;
use doctree;
@@ -158,7 +159,7 @@ pub struct Cache {
priv parent_stack: ~[ast::NodeId],
priv search_index: ~[IndexItem],
priv privmod: bool,
priv public_items: HashSet<ast::NodeId>,
priv public_items: NodeSet,
}
/// Helper struct to render all source code to HTML pages
@@ -235,7 +236,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
// Crawl the crate to build various caches used for the output
let mut cache = local_data::get(::analysiskey, |analysis| {
let public_items = analysis.map(|a| a.public_items.clone());
let public_items = public_items.unwrap_or(HashSet::new());
let public_items = public_items.unwrap_or(NodeSet::new());
Cache {
impls: HashMap::new(),
typarams: HashMap::new(),