Commit eb259e8
authored
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%.1 parent 1efaa73 commit eb259e8
3 files changed
Lines changed: 34 additions & 66 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | 39 | | |
77 | 40 | | |
78 | 41 | | |
79 | 42 | | |
80 | | - | |
81 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
82 | 49 | | |
83 | 50 | | |
84 | 51 | | |
85 | 52 | | |
86 | 53 | | |
87 | 54 | | |
88 | | - | |
89 | | - | |
90 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
91 | 68 | | |
92 | | - | |
| 69 | + | |
93 | 70 | | |
94 | 71 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | 72 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 73 | + | |
106 | 74 | | |
107 | 75 | | |
108 | 76 | | |
| |||
112 | 80 | | |
113 | 81 | | |
114 | 82 | | |
115 | | - | |
| 83 | + | |
116 | 84 | | |
117 | | - | |
118 | | - | |
119 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
120 | 88 | | |
121 | | - | |
| 89 | + | |
122 | 90 | | |
123 | 91 | | |
| 92 | + | |
124 | 93 | | |
125 | 94 | | |
126 | 95 | | |
| |||
180 | 149 | | |
181 | 150 | | |
182 | 151 | | |
| 152 | + | |
| 153 | + | |
183 | 154 | | |
184 | 155 | | |
185 | 156 | | |
| |||
285 | 256 | | |
286 | 257 | | |
287 | 258 | | |
288 | | - | |
| 259 | + | |
289 | 260 | | |
290 | 261 | | |
291 | 262 | | |
| |||
299 | 270 | | |
300 | 271 | | |
301 | 272 | | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | 273 | | |
308 | 274 | | |
309 | 275 | | |
310 | 276 | | |
| 277 | + | |
| 278 | + | |
311 | 279 | | |
312 | 280 | | |
313 | 281 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
630 | 630 | | |
631 | 631 | | |
632 | 632 | | |
| 633 | + | |
633 | 634 | | |
634 | 635 | | |
635 | 636 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
| 160 | + | |
161 | 161 | | |
162 | | - | |
163 | 162 | | |
164 | 163 | | |
165 | 164 | | |
| |||
0 commit comments