And as the essay mentions there are also “hints” you can give the compiler to fold bounds checks which may be sufficient.
better at Go to ship apps — none of that needed. actually opposite. the less complexity and low level details you hardcode yourself, the better. chances are, this low-level tech debt will bite you back when you have no time to deal with it. keep it simple.
better at Go to work with internals of Go/compilers/runtime — yes, but do you plan to ship one? or why it is needed at all? or do you work at Go core at Google?
> probably you do not need to do any of that.
Indeed, I find that at least in my case, on a pretty average Intel machine these checks add very little overhead, especially compared to the benefits. I do not really understand how the examples in the blog post can get 100% (1st one) or even 10% (2nd one) faster.
(And yeah, I know that the obvious solution is to develop these tools in C/C++: I am just exploring the capabilities of Go in that space).
proc littleEndian(b: openarray[byte]): uint32 =
{.push boundChecks: off.}
return uint32(b[0]) or (uint32(b[1]) shl 8) or (uint32(b[2]) shl 16) or (uint32(b[3]) shl 24)
{.pop.}
And GCC is smart enough to reduce it to a single operation: 000000000000bf80 <littleEndian_u0__session95202695079520951784538200>:
bf80: 8b 07 mov (%rdi),%eax
bf82: c3 retArticles about GoLang assembly language[1] are particularly vexing because the instruction parameters are bass-ackwards - source, destination - like AT&T syntax, but register references are missing their % sigil and so appear to be MASM-style[2].
Authors blogging from deep inside some technical tent should take pity on readers who are not so deeply in the tent and offer a brief primer on assumed knowledge.
Any mistakes in the above should be viewed as confirmation of my confusion.
[0] https://en.wikipedia.org/wiki/X86_calling_conventions
Because what the IT infrastructure needs is more CVEs.
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 little endian.
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 greater changes to be fine with 'unsafe'.
Like, I have a hardcoded 1024-byte buffer, my loop is hardcoded so its index increases modulo 1024, it can never run off the end any more than you can overtake your own bike chain?
5701652400•16h ago
porridgeraisin•15h ago
5701652400•15h ago
delamon•14h ago
porridgeraisin•14h ago