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?

@kestred

kestred commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

@fitzgen is this the right thing to run for this kind of change?


MacBook Pro, Apple M5 Pro, 18 cores, 64 GB, macOS 26.6.2, amd64

Default suite (29 programs), 100 iterations, significance level 0.01

* Compilation geomean +0.15% (not significant)
  * No statistically significant per-program change
* Execution geomean +0.02% (not significant)
  * No statistically significant per-program change
* Compilation cycles -0.9% (99% confidence)

AMD EPYC-Genoa, 16 vCPUs, 30 GB, Ubuntu 26.04.1 LTS, x86_64

Default suite (29 programs), 10 iterations, significance level 0.01, parallel compilation off

* Compilation geomean -0.026% (99% confidence, significant); weighted total -0.056%
  * Improvements:
     * rust-wasmprinter -1.22%
     * tinygo-regex -0.26%
     * shootout-switch -0.12%
     * starlingmonkey-markdown -0.03%
  * No program regresses by more than 0.07% (most +0.02..0.07%, individually insignificant)
* Execution instructions unchanged to six digits, so generated code is identical
* Compilation cycles -1.2% geomean, not significant (shared box, load 1-5)

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