Some small perf improvements (#95)
* Do conflict-set hash lookups once, not twice This makes the small wasmtime bz2 benchmark 1% faster, per Hyperfine and Sightglass. The effect disappears into the noise on larger benchmarks. * Inline PosWithPrio::key When compiling the pulldown-cmark benchmark from Sightglass, this is the single most frequently called function: it's invoked 2.5 million times. Inlining it reduces instructions retired by 1.5% on that benchmark, according to `valgrind --tool=callgrind`. This patch is "1.01 ± 0.01 times faster" according to Hyperfine for the bz2, pulldown-cmark, and spidermonkey benchmarks from Sightglass. Sightglass, in turn, agrees that all three benchmarks are 1.01x faster by instructions retired, and the first two are around 1.01x faster by CPU cycles as well. * Inline and simplify AdaptiveMap::expand Previously, `get_or_insert` would iterate over the keys to find one that matched; then, if none did, iterate over the values to check if any are 0; then iterate again to remove all zero values and compact the map. This commit instead focuses on picking an index to use: preferably one where the key already exists; but if it's not in the map, then an unused index; but if there aren't any, then an index where the value is zero. As a result this iterates the two arrays at most once each, and both iterations can stop early. The downside is that keys whose value is zero are not removed as aggressively. It might be worth pruning such keys in `IndexSet::set`. Also: - `#[inline]` both implementations of `Iterator::next` - Replace `set_bits` with using the `SetBitsIter` constructor directly These changes together reduce instructions retired when compiling the pulldown-cmark benchmark by 0.9%.
This commit is contained in:
@@ -157,9 +157,8 @@ impl<'a, F: Function> Env<'a, F> {
|
||||
// conflicts list.
|
||||
let conflict_bundle = self.ranges[preg_range.index()].bundle;
|
||||
trace!(" -> conflict bundle {:?}", conflict_bundle);
|
||||
if !self.conflict_set.contains(&conflict_bundle) {
|
||||
if self.conflict_set.insert(conflict_bundle) {
|
||||
conflicts.push(conflict_bundle);
|
||||
self.conflict_set.insert(conflict_bundle);
|
||||
max_conflict_weight = std::cmp::max(
|
||||
max_conflict_weight,
|
||||
self.bundles[conflict_bundle.index()].cached_spill_weight(),
|
||||
|
||||
Reference in New Issue
Block a user