runtime (gc_blocks.go): use best-fit allocation

The allocator originally just looped through the blocks until it found a sufficiently-long range.
This is simple, but it fragments very easily and can degrade to a full heap scan for long requests.

Instead, we now maintain a sorted nested list of free ranges by size.
The allocator will select the shortest sufficient-length range, generally reducing fragmentation.
This data structure can find a range in time directly proportional to the requested length.
This commit is contained in:
Nia Waldvogel
2025-11-30 22:17:57 -05:00
committed by Ron Evans
parent b37535bcfb
commit 8fcf3658b1
2 changed files with 195 additions and 86 deletions
+3 -3
View File
@@ -42,9 +42,9 @@ func TestBinarySize(t *testing.T) {
// This is a small number of very diverse targets that we want to test.
tests := []sizeTest{
// microcontrollers
{"hifive1b", "examples/echo", 3568, 280, 0, 2268},
{"microbit", "examples/serial", 2630, 342, 8, 2272},
{"wioterminal", "examples/pininterrupt", 7175, 1493, 116, 6912},
{"hifive1b", "examples/echo", 3808, 280, 0, 2268},
{"microbit", "examples/serial", 2790, 342, 8, 2272},
{"wioterminal", "examples/pininterrupt", 7327, 1493, 116, 6912},
// TODO: also check wasm. Right now this is difficult, because
// wasm binaries are run through wasm-opt and therefore the