Stream: git-wasmtime

Topic: wasmtime / PR #13710 Cranelift: use a BTreeMap for JITMod...


view this post on Zulip Wasmtime GitHub notifications bot (Jun 22 2026 at 20:44):

mkschreder opened PR #13710 from swedishembedded:cranelift-jit-finalize-btreemap to bytecodealliance:main:

Let's make cranelift a little faster when booting JITed linux :)

Currently JITModule resolves a PC back to its defining function (for exception unwinding) via a Vec<(start, end, FuncId)> that was re-sorted in full on every finalize_definitions call. Code that defines and finalizes functions one at a time therefore paid an O(n) sort per finalize, i.e. O(n^2) overall.

I replace the vector with a BTreeMap keyed on the start address. Inserts stay sorted incrementally (O(log n)) and the lookup becomes an O(log n) range query, so finalizing is linear in the number of functions with no sort.

Noticible speedup is observed without any (obvious) problems. I think the change makes sense and I don't see why it wouldn't simply just get rid of O(n^2) complexity without any other issues.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 22 2026 at 20:44):

mkschreder requested cfallin for a review on PR #13710.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 22 2026 at 20:44):

mkschreder requested wasmtime-compiler-reviewers for a review on PR #13710.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 22 2026 at 22:20):

github-actions[bot] added the label cranelift on PR #13710.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2026 at 15:37):

:thumbs_up: cfallin submitted PR review:

Reasonable change and looks good -- thanks! (FWIW this is more or less how Wasmtime's address map data structures work so it's neat to see cranelift-jit have convergent evolution here.)

Just some style notes re: the comments below, then happy to merge.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2026 at 15:37):

:speech_balloon: cfallin created PR review comment:

No need for the detailed explainer here -- makes sense when justifying the change, but doesn't have to live in the source forever. Just the format note (map from start addr to end addr and function) is fine.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2026 at 15:37):

:speech_balloon: cfallin created PR review comment:

Likewise here -- comment only makes sense in context of the diff, no need to keep this forever.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 24 2026 at 06:13):

:memo: mkschreder submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 24 2026 at 06:13):

:speech_balloon: mkschreder created PR review comment:

Thank you for your feedback. Don't you think though that the comment makes this choice much more obvious and potentially leads to similar choices being made more often in the future? I have the belief that the better code decisions are documented in place the better culture it creates over time because people (or machines) look at the comment like that and then realize that somewhere in a different place the same solution makes sense as well. Without the comment, it becomes an opaque decision burried in a git commit. Happy to remove the comments but I just think they do more good than bad.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 24 2026 at 21:01):

:memo: cfallin submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 24 2026 at 21:01):

:speech_balloon: cfallin created PR review comment:

Well, no, I don't think we need this level of detail -- it describes the past implementation and its impact ("re-sort of the whole table ... which made ..."). Level of commenting is always a subjective call, and I am all for detailed comments where things are tricky, but a BTreeMap sorted by address is common enough throughout all of Wasmtime+Cranelift that we don't need this; rather, overly verbose comments like this look (in context of our local style) like an indication of something non-obvious, and take time to read and digest, which is a net negative for a straightforward idiom, IMHO. The comment describing what they keys and values are is enough.

Part of my thinking here is informed by recent LLM-isms too: they have a tendency to be extraordinarily verbose, and dump point-in-time thoughts in comments everywhere, which over time makes the code extremely difficult to read, ironically. So I think we need to apply some judgment and be a bit judicious in exchange.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 25 2026 at 13:33):

:memo: mkschreder submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 25 2026 at 13:33):

:speech_balloon: mkschreder created PR review comment:

Done.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 25 2026 at 13:33):

:memo: mkschreder submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 25 2026 at 13:33):

:speech_balloon: mkschreder created PR review comment:

@cfallin done.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 25 2026 at 13:33):

mkschreder updated PR #13710.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 25 2026 at 23:21):

:memo: cfallin submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 25 2026 at 23:21):

:speech_balloon: cfallin created PR review comment:

It looks like you deleted the entire comment. From above: "Just the format note (map from start addr to end addr and function) is fine."

Could you add back that note?

view this post on Zulip Wasmtime GitHub notifications bot (Jun 26 2026 at 09:02):

mkschreder updated PR #13710.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 26 2026 at 09:02):

:memo: mkschreder submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 26 2026 at 09:02):

:speech_balloon: mkschreder created PR review comment:

Added back "// Search the sorted code-ranges for the PC."

view this post on Zulip Wasmtime GitHub notifications bot (Jun 26 2026 at 09:03):

:memo: mkschreder submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 26 2026 at 09:03):

:speech_balloon: mkschreder created PR review comment:

Not sure what you mean by "note". Please paste the exact wording of the comment you want along with line number where it should be and I will update the commit.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 26 2026 at 14:37):

mkschreder requested cfallin for a review on PR #13710.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 26 2026 at 16:11):

:memo: cfallin submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 26 2026 at 16:11):

:speech_balloon: cfallin created PR review comment:

No, I did not ask for "// Search the sorted ..." to be added back in, and that is an incorrect comment now, since we do not have a sorted list. Please remove that.

Please add back the first half of the comment on the struct field. This is what I mean by "format note (map from start addr to end addr and function)". Your original wording is fine: "Map from a function's start address to its (end address, FuncId), used to resolve a PC back to its function for exception unwinding."

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 12:32):

:memo: mkschreder submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 12:32):

:speech_balloon: mkschreder created PR review comment:

The map is implicitly sorted though, so I would say that the comment is still correct.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 12:45):

mkschreder updated PR #13710.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 12:46):

:memo: mkschreder submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 12:46):

:speech_balloon: mkschreder created PR review comment:

Added the comment to struct member.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 12:47):

:memo: mkschreder submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 12:47):

:speech_balloon: mkschreder created PR review comment:

@cfallin no offence, but I think we are nitpicking at this point :)

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 16:23):

mkschreder updated PR #13710.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 16:23):

:memo: mkschreder submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 16:23):

:speech_balloon: mkschreder created PR review comment:

Done.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 17:45):

:thumbs_up: cfallin submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 17:45):

cfallin added PR #13710 Cranelift: use a BTreeMap for JITModule code ranges to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 17:56):

:memo: cfallin submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 17:56):

:speech_balloon: cfallin created PR review comment:

no offence, but I think we are nitpicking at this point :)

Well, no, just trying to get the comment I had originally asked for, no more, no less. Thanks for making the change!

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 18:03):

github-merge-queue[bot] removed PR #13710 Cranelift: use a BTreeMap for JITModule code ranges from the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 18:05):

cfallin added PR #13710 Cranelift: use a BTreeMap for JITModule code ranges to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 18:30):

:check: cfallin merged PR #13710.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2026 at 18:30):

cfallin removed PR #13710 Cranelift: use a BTreeMap for JITModule code ranges from the merge queue.


Last updated: Jul 29 2026 at 05:03 UTC