Skip to content

Commit fdcf7b6

Browse files
authored
Avoid indexing and use iteration (#98)
...while still appeasing the borrow checker by taking spillsets out of `self` and then putting them back in again when we're done. I was just doing this to enable playing with some data structures in follow up commits, but decided to benchmark this commit as-is and found 2-4% speed ups to Cranelift compilation! ``` compilation :: instructions-retired :: benchmarks/bz2/benchmark.wasm Δ = 39946528.13 ± 38398.29 (confidence = 99%) no-index.so is 1.04x to 1.04x faster than main.so! [985704952 985984130.24 986180413] main.so [945649144 946037602.11 946262076] no-index.so compilation :: instructions-retired :: benchmarks/pulldown-cmark/benchmark.wasm Δ = 48413802.56 ± 34288.05 (confidence = 99%) no-index.so is 1.03x to 1.03x faster than main.so! [1593663899 1593926801.92 1594246604] main.so [1545196678 1545512999.36 1545802144] no-index.so compilation :: instructions-retired :: benchmarks/spidermonkey/benchmark.wasm Δ = 841028066.56 ± 253404.59 (confidence = 99%) no-index.so is 1.02x to 1.02x faster than main.so! [34798712681 34801346430.28 34802786661] main.so [33958847844 33960318363.72 33962177143] no-index.so ```
1 parent b4eedf3 commit fdcf7b6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/ion/spill.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ impl<'a, F: Function> Env<'a, F> {
8989
spillslot: SpillSlotIndex,
9090
) {
9191
self.spillsets[spillset.index()].slot = spillslot;
92-
for i in 0..self.spillsets[spillset.index()].vregs.len() {
93-
// don't borrow self
94-
let vreg = self.spillsets[spillset.index()].vregs[i];
92+
93+
// Take `spillsets` to avoid a conflicting borrow of `self`.
94+
let spillsets = std::mem::take(&mut self.spillsets);
95+
96+
for vreg in &spillsets[spillset.index()].vregs {
9597
trace!(
9698
"spillslot {:?} alloc'ed to spillset {:?}: vreg {:?}",
9799
spillslot,
@@ -112,6 +114,10 @@ impl<'a, F: Function> Env<'a, F> {
112114
.insert(LiveRangeKey::from_range(&entry.range), entry.index);
113115
}
114116
}
117+
118+
// Replace `spillsets`.
119+
let default = std::mem::replace(&mut self.spillsets, spillsets);
120+
debug_assert!(default.is_empty());
115121
}
116122

117123
pub fn allocate_spillslots(&mut self) {

0 commit comments

Comments
 (0)