Skip to content

Splice merged ranges in without sorting when they fit between two ranges - #283

Open
kestred wants to merge 1 commit into
bytecodealliance:mainfrom
kestred:merging-bundles
Open

kestred wants to merge 1 commit into
bytecodealliance:mainfrom
kestred:merging-bundles

Conversation

@kestred

@kestred kestred commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #276.

merge_bundles inserts a single range by binary search, but it concatenates and re-sorts the whole list for any
bundle with more than one range. A value carried through loops in a row merges into one growing bundle, so each merge
re-sorts that bundle again. This splices from_list in at the binary-search point whenever it fits between two
adjacent ranges of to, and sorts only when the two lists interleave.

My ordinary test corpus (~20 programs of various shapes) compile with 0.13% fewer instructions.

For pathological programs, instructions retired by merging bundles with N loops in a row:

Loops Before After
1,024 0.23G 0.08G
16,384 71.9G 18.7G

@fitzgen

fitzgen commented Nov 17, 2026

Copy link
Copy Markdown
Member

Can you do a Sightglass run for this as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: merging bundles takes quadratic time in the number of blocks

2 participants