Repository navigation
compiler: avoid byte slice copies in mixed string comparisons - #5784
Conversation
|
From a corrrectness standpoint the test corpus is happy with this change, but we should figure out what's happening with the AVR build (and also the binary size test failed CI). |
c535c5d to
26cbd22
Compare
The AVR build needs an exception, like math.go, because after inlining main.main is large enough it needs more stack than simavr provides. |
26cbd22 to
ce70b56
Compare
18a32c9 to
2019822
Compare
4fee9cf to
42c617d
Compare
Compare string(a) with any string operand without copying the []byte operand when nothing between the conversion and the comparison can change it. tinygo-org#5765 and tinygo-org#5773 needed both operands to be []byte conversions, but Go's gc compiler [marks each operand on its own](https://github.com/golang/go/blob/go1.27.2/src/cmd/compile/internal/walk/order.go#L1447-L1456), and this change does the same. The safety check from tinygo-org#5765 does not change, so a call, store, load, or slice between the conversion and the comparison keeps the copy. On cortex-m-qemu with -opt=z, the size corpus code drops from 9923 to 9907 bytes.
42c617d to
72a6963
Compare
|
@dgryski @deadprogram after a bunch of side quests this is now ready for review. |
|
Thanks @davecheney. I ran the tests locally. The following is edited from an automated review:
WDYT? |
deadprogram
left a comment
There was a problem hiding this comment.
My comments being just comments, this PR is looking good to me. Now merging, thank you @davecheney
|
@deadprogram thanks for your comments
fortunately I have #5937 waiting in the wings
I'll take this under advisement. I'll send a PR to switch the memory size arithmetic. |
The test read exact byte counts from runtime.MemStats, so it needed the conservative collector, and a change in how that collector counts bytes could break it, as deadprogram said in #5784 (comment). testing.AllocsPerRun gives the same count with every collector, so the test can also run with the default collector of each target, which is boehm on hosts.
The test read exact byte counts from runtime.MemStats, so it needed the conservative collector, and a change in how that collector counts bytes could break it, as deadprogram said in tinygo-org#5784 (comment). testing.AllocsPerRun gives the same count with every collector, so the test can also run with the default collector of each target, which is boehm on hosts.
Compare string(a) with any string operand without copying the []byte operand when nothing between the conversion and the comparison can change it.
#5765 and #5773 needed both operands to be []byte conversions, but Go's gc compiler marks each operand on its own, and this change does the same.
The safety check from #5765 does not change, so a call, store, load, or slice between the conversion and the comparison keeps the copy.
On cortex-m-qemu with -opt=z, the size corpus code drops from 9923 to 9907 bytes.