Nice, my push for actually using the sha256 instructions on amd64 finally got released. 3x-4x increase in hash speed on most x86 which is really nice for content addressable storage use cases like handling container images.
Huh, that is interesting how they do that. They are enabling SHA instruction support based on CPUID and without respect to the value of GOAMD64. I did not realize Go was doing that.
Go 1.21 Release Candidate
41–50 of 236 posts
Re: Go 1.21 Release Candidate
#42Huh, I'm glad to see generic Min/Max functions, but the fact that they're built-ins is a little odd to me. I would have expected them to put a generic math library into the stdlib instead. The fact the stdlib math package only works with float64s has always struck me as a poorly thought out decision.
func clamp(x float64) float64 {
return max(0, min(1, x))
}
With ordinary functions, the arguments are assigned types too soon, and you get integer types for 0 and 1 in the above code. In C++ you might make the types explicit: template
T clamp(T x) {
return std::max(0, std::min(1, x));
}
That’s not meant to be exactly the way you’d write these functions, but just a little bit of sample code to show how the typing is different.Re: Go 1.21 Release Candidate
#43Wait is this now heap allocating a value in every iteration of every loop? I hope that allocation is optimized out in every case where there isn't a closure over the loop variable?
Re: Go 1.21 Release Candidate
#44Re: Go 1.21 Release Candidate
#45Wait is this now heap allocating a value in every iteration of every loop? I hope that allocation is optimized out in every case where there isn't a closure over the loop variable?
Re: Go 1.21 Release Candidate
#46Wait is this now heap allocating a value in every iteration of every loop? I hope that allocation is optimized out in every case where there isn't a closure over the loop variable?
In fact, you can enable warnings/logs that indicate whether code that is affected by the loopvar experiment results in a stack-allocated or heap-allocated loop variable: https://github.com/golang/go/wiki/LoopvarExperiment#can-i-se...
I imagine that the current workarounds for this issue also end up with heap-allocated variables in many cases.
Re: Go 1.21 Release Candidate
#47I'm a bit surprised that the slog package was added to the stdlib, but it does seem to use the API that I think is the most ergonomic across libraries I saw in Go (specifically, varargs for key values, and the ability to create subloggers using .With), so I guess it's nice most of the community will standardize around it. If all goes well, you won't have different libraries using different loggers anymore, in some no…
Re: Go 1.21 Release Candidate
#48Why is map copy "dst, src" vs "src, dst"?
Note that the order mimics variable assignment. You copy an integer with:
var src, dest int
dest = src // dest first, src second
I appreciate the consistency.Re: Go 1.21 Release Candidate
#49I enjoy Go so much. It is almost perfect language for getting things done, but I still can't understand some design choices. Does someone knows why Go uses env variables (like GOOS and GOARCH) instead command line arguments?
Re: Go 1.21 Release Candidate
#50Why is map copy "dst, src" vs "src, dst"?