fitzgen opened PR #13923 from fitzgen:avoid-some-hashmaps-when-lowering to bytecodealliance:main:
This commit implements three optimizations for lowering's hot path:
Compute instruction constants on demand instead of caching them in a hashmap. The well-predicted match on a dense
dfg.instselement is cheaper than the random-access hash probe, and this also removes the cached hashmap construction at setup too.Make
side_effect_inst_entry_colorsa denseSecondaryMap<Inst, InstColor>instead of a hashmap.cur_colorreaches at least 1 before processing any instruction, so the defaultInstColor(0)is available as a "not side-effecting" sentinel. This replaces hash probing with array indexing and letsget_value_as_source_or_constandlower_clif_blockreuse one dense read for both the side-effect test and the color, dropping a redundanthas_lowering_side_effectrecompute per source instruction.Iterate the lowered block order by index in
Lower::lowerinstead of cloning it into aSmallVec(that likely must heap allocate), removing a per-function allocation.<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
fitzgen requested cfallin for a review on PR #13923.
fitzgen requested wasmtime-compiler-reviewers for a review on PR #13923.
:thumbs_up: cfallin submitted PR review:
Thanks!
:speech_balloon: cfallin created PR review comment:
Subjective style nit but: no need for the history-narrative comment here IIRC -- most of our algorithms compute what they need on demand, and caching is the exception that would need explanation.
fitzgen updated PR #13923.
fitzgen has enabled auto merge for PR #13923.
fitzgen added PR #13923 Cranelift: Avoid some hashmaps on the lowering hot path to the merge queue.
github-merge-queue[bot] removed PR #13923 Cranelift: Avoid some hashmaps on the lowering hot path from the merge queue.
fitzgen added PR #13923 Cranelift: Avoid some hashmaps on the lowering hot path to the merge queue.
:check: fitzgen merged PR #13923.
fitzgen removed PR #13923 Cranelift: Avoid some hashmaps on the lowering hot path from the merge queue.
Last updated: Jul 29 2026 at 05:03 UTC