Live data from Hacker News

Eliminating Go bounds checks with unsafe

blog.andr2i.com

21–23 of 23 posts

Re: Eliminating Go bounds checks with unsafe

#21
post #6

I like reading articles like this, but as per usual, I also find these articles frustrating to read because they don't specify calling conventions[0] (which are many and varied) - particularly the allocation of arguments to registers and the stack frame. Articles about GoLang assembly language[1] are particularly vexing because the instruction parameters are bass-ackwards - source, destination - like AT&T syntax, but…

Yeah that’s the infamous curse of knowledge.. it’s quite hard to imagine oneself as a beginner again (although the skill can be learned.)

Re: Eliminating Go bounds checks with unsafe

#22
post #16

The article should note this: it's important that you don't go adding other/all little endian platforms to that go:build line. The article is correct, but this code is only valid for platforms that allow unaligned access. You can get the full list of platforms that Go considers safe for this from unalignedOK here: https://go.dev/src/cmd/compile/internal/ssa/config.go You want the intersection of unalignedOK with litt…

Thank you. I've added your comment to the essay.

Re: Eliminating Go bounds checks with unsafe

#23
post #20

Nice article Andrii. I see from previous articles https://blog.andr2i.com/posts/2026-06-22-optimization-catalo... > that you can identify and validate bottlenecks which you can optimize. For more general Go practitioners like me, is there any harness/tooling I can bring into my projects to identify these bottlenecks (aside from profiling if any). More specifically, tooling that identifies workflows that actually have…

Thanks! Good question, I don't think such a tool exists. Such a tool would require a mathematical proof of an invariant that all the accesses are in bounds. The closest thing is the compiler's own bounds-check elimination proof engine. It eliminates the check when it can prove the checks aren't necessary and sometimes you can help it with hints like `_ = b[i+3]`. But then you don't need unsafe at all, which is the point: unsafe is the last resort.
Post reply on HN