4 ms·
There are cases where the Go compiler generates horrors, and the only workaround is to write your code in asm. Here's one example: // imagine a for-loop aroun
by jusssi 11y ago
There are cases where the Go compiler generates horrors, and the only workaround is to write your code in asm.
Here's one example:
// imagine a for-loop around this
s := foo[i:i+4]
s[3], s[2], s[1], s[0] = s[0], s[1], s[2], s[3]
The reasonable assumption is that the second line generates either zero, one, or four bounds checks on s. However, the Go compiler likes to be sure, and turns it into 8 bounds checks.
I agree it's not a typical for a server to spend the majority of it's time swapping bytes. In the rare case that happens, you're going to hate the compiler for not being smarter.
EDIT: fixed formatting of the example