]> git.lizzy.rs Git - rust.git/commit
Avoid repeated HashMap lookups in `opt_normalize_projection_type`.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 16 May 2018 10:59:27 +0000 (20:59 +1000)
committerNicholas Nethercote <nnethercote@mozilla.com>
Wed, 16 May 2018 23:34:20 +0000 (09:34 +1000)
commitf778bdefdd9663aa78c31ffc7773e31bcae4fb39
treeffa3ff5d6f360749f1753c0d7e8b56b79432d5fb
parent6fc409ed0938cd2f501642abcaa675977fa5035a
Avoid repeated HashMap lookups in `opt_normalize_projection_type`.

There is a hot path through `opt_normalize_projection_type`:
- `try_start` does a cache lookup (#1).
- The result is a `NormalizedTy`.
- There are no unresolved type vars, so we call `complete`.
- `complete` does *another* cache lookup (#2), then calls
  `SnapshotMap::insert`.
- `insert` does *another* cache lookup (#3), inserting the same value
  that's already in the cache.

This patch optimizes this hot path by introducing `complete_normalized`,
for use when the value is known in advance to be a `NormalizedTy`. It
always avoids lookup #2. Furthermore, if the `NormalizedTy`'s
obligations are empty (the common case), we know that lookup #3 would be
a no-op, so we avoid it, while inserting a Noop into the `SnapshotMap`'s
undo log.
src/librustc/traits/project.rs
src/librustc_data_structures/snapshot_map/mod.rs