From 966401a8e7e263a4cfbeefce3891177ce9231448 Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Thu, 22 Oct 2026 12:08:03 +1100 Subject: [PATCH] builder: add size tests for startup work removed by interp Recent changes that let interp move startup work to compile time did not show up in TestBinarySize, so their savings went unmeasured and a regression would go unnoticed. These samples cover the RP2 targets, ESP32-C3, slice growth and os. Their sizes match on Go 1.25 to 1.27. Run against the commits before and after each change, these rows show (code/rodata bytes, opt=z): - #5837 RP2 PLL: pico -1308/-548, pico2 -1128/-552 (opt=2 code -5 to -6 KB). Visible only with #5975. - #5963 llvm.ctlz: pico -818/-142, pico2 -754/-142, size-slice -163/-5. - #5973 os temp file seed: pico2 size-os -16 (opt=2 -32). --- builder/sizes_test.go | 12 ++++++++++++ builder/testdata/binary-size.txt | 26 ++++++++++++++++++-------- builder/testdata/size-os/main.go | 7 +++++++ builder/testdata/size-slice/main.go | 17 +++++++++++++++++ 4 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 builder/testdata/size-os/main.go create mode 100644 builder/testdata/size-slice/main.go diff --git a/builder/sizes_test.go b/builder/sizes_test.go index 0f513cc27c..6a6f8d8fcf 100644 --- a/builder/sizes_test.go +++ b/builder/sizes_test.go @@ -75,6 +75,18 @@ func TestBinarySize(t *testing.T) { {target: "microbit", path: "examples/serial", opt: "z"}, {target: "wioterminal", path: "examples/pininterrupt", opt: "z"}, + {target: "pico", path: "examples/serial", opt: "z"}, + {target: "pico", path: "examples/serial", opt: "2"}, + {target: "pico2", path: "examples/serial", opt: "z"}, + {target: "pico2", path: "examples/serial", opt: "2"}, + {target: "esp32c3-generic", path: "examples/serial", opt: "z"}, + {target: "esp32c3-generic", path: "examples/serial", opt: "2"}, + + {target: "cortex-m-qemu", path: "./testdata/size-slice", opt: "z"}, + {target: "cortex-m-qemu", path: "./testdata/size-slice", opt: "2"}, + {target: "pico2", path: "./testdata/size-os", opt: "z"}, + {target: "pico2", path: "./testdata/size-os", opt: "2"}, + {target: "cortex-m-qemu", path: "./testdata/size-corpus", opt: "z"}, {target: "cortex-m-qemu", path: "./testdata/size-corpus", opt: "2"}, {target: "riscv-qemu", path: "./testdata/size-corpus", opt: "z"}, diff --git a/builder/testdata/binary-size.txt b/builder/testdata/binary-size.txt index ebf3394095..b5e1676839 100644 --- a/builder/testdata/binary-size.txt +++ b/builder/testdata/binary-size.txt @@ -1,8 +1,18 @@ -target package opt code rodata data bss -hifive1b examples/echo z 4558 402 0 2276 -microbit examples/serial z 3001 439 8 2272 -wioterminal examples/pininterrupt z 7802 1686 136 7280 -cortex-m-qemu ./testdata/size-corpus z 9907 1301 80 4188 -cortex-m-qemu ./testdata/size-corpus 2 17482 862 72 4188 -riscv-qemu ./testdata/size-corpus z 17540 1028 88 16660 -riscv-qemu ./testdata/size-corpus 2 25160 744 80 16644 +target package opt code rodata data bss +hifive1b examples/echo z 4558 402 0 2276 +microbit examples/serial z 3001 439 8 2272 +wioterminal examples/pininterrupt z 7802 1686 136 7280 +pico examples/serial z 7673 1071 112 5616 +pico examples/serial 2 16298 862 108 5616 +pico2 examples/serial z 6468 1172 112 5608 +pico2 examples/serial 2 15925 979 108 5608 +esp32c3-generic examples/serial z 5864 768 0 8664 +esp32c3-generic examples/serial 2 9888 600 8 8672 +cortex-m-qemu ./testdata/size-slice z 3087 793 4 4168 +cortex-m-qemu ./testdata/size-slice 2 7331 341 4 4168 +pico2 ./testdata/size-os z 6153 1207 128 5592 +pico2 ./testdata/size-os 2 15240 1016 128 5592 +cortex-m-qemu ./testdata/size-corpus z 9907 1301 80 4188 +cortex-m-qemu ./testdata/size-corpus 2 17482 862 72 4188 +riscv-qemu ./testdata/size-corpus z 17540 1028 88 16660 +riscv-qemu ./testdata/size-corpus 2 25160 744 80 16644 diff --git a/builder/testdata/size-os/main.go b/builder/testdata/size-os/main.go new file mode 100644 index 0000000000..f481dc0224 --- /dev/null +++ b/builder/testdata/size-os/main.go @@ -0,0 +1,7 @@ +package main + +import "os" + +func main() { + os.Stdout.WriteString("hello\n") +} diff --git a/builder/testdata/size-slice/main.go b/builder/testdata/size-slice/main.go new file mode 100644 index 0000000000..0418348132 --- /dev/null +++ b/builder/testdata/size-slice/main.go @@ -0,0 +1,17 @@ +package main + +var values = makeValues() + +func makeValues() []byte { + var values []byte + for i := 0; i < 32; i++ { + values = append(values, byte(i)) + } + return values +} + +func main() { + for _, value := range values { + println(value) + } +}