On Wed, Oct 9, 2024 at 8:51 PM Nico Braun <rainbowst...@gmail.com> 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 coded with micro 
> optimizations.
>
> For example, disabling bound checks in some methods, by doing something `like 
> _ = s[10]`.
>
> Or trying to use function arguments that they will likely end up on the stack 
> and not on the heap, by playing the escape analyzer. I.e. pass buffer to 
> io.Reader. Or sometimes, dont pass interface because it is hard for the 
> compiler to understand that the interface doesnt escape.
>
> I wonder, if I code like this, is this considered premature optimization. Or 
> is more like good habbit?

In the standard library it's only done with benchmarks and profiles
that show that it makes a difference.  So I would say that it's not
premature optimization, it's just optimization.

Doing that kind of bounds check avoidance in brand new code without
benchmarking or profiling might be reasonably called premature
optimization.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWovogejv1ZZ1AVWxVmip-wB6EmpiV3C60cDveQKao4KA%40mail.gmail.com.

Reply via email to