If you write `_ = s[10]` and len(s)<11, that line will panic. So after that
line, the compiler can assume that len(s)>=11 and omit bounds check for
smaller indices.
That is, if you write
f(s[0])
f(s[1])
…
f(s[10])
That will be 11 bounds checks, as depending on what exactly len(s) is, a
different
Hi, I was under the impression that this, ` _ = s[10] `, happens at compile
time. But that probably doesnt make sense. We dont know the length of all
slices at compile time.
Then, what is this actually improving? Does the compiler see there will be
a bound check, so it doesnt produce instructi
On Thursday, October 10, 2024 at 11:51:02 AM UTC+8 Nico Braun wrote:
Hi, recently I became very self aware of potential performance implications
my code might have.
In go there are a few key concepts, like escape analysis and bound checks.
If you check the standard library, you can see it was