Re:Expectations for generics in Go 1.18
by mseepgood on Wednesday October 27, 2021 @09:54PM
(#29021426)
GC Shape Stenciling, a hybrid of stenciling and dictionaries: https://go.googlesource.com/proposal/+/refs/heads/master/des...
[ Parent
| on HN ]
How does that compare to other approaches for generics? I know that you can do monomorphisation, which usually increases the executable size and compilation time, and usually gives faster code, but I don't know about other approcahes.
Re:Expectations for generics in Go 1.18
by mseepgood on Thursday October 28, 2021 @06:06AM
(#29024207)
The two approaches are stenciling (what you call monomorphisation) and dictionaries. Stenciling/monomorphization increases binary size, compilation time and TLB/cache pressure. The dictionaries-only approach has more runtime cost. This hybrid is a middle ground of both.
Re:Expectations for generics in Go 1.18
by rustnote on Thursday October 28, 2021 @12:13AM
(#29022299)
So there's a runtime cost for using generics?
The linked article is a proposal but at least when I tried Go a couple of weeks ago, it did not use that approach and to the best of my knowledge that proposal has not yet been implemented. Instead as of now Go uses the straight forward approach of generating one implementation for every instantiation just like C++ compilers do.
The upside is there is no runtime cost to using generics, the downside is there is significant compile time and link time cost to generics.
> the downside is there is significant compile time and link time cost to generics.
Are we talking statistically significant or productivity significant compile time cost? Go has a fairly fast compiler, it would be a shame if generics made that a less stand-out feature.
Re:Expectations for generics in Go 1.18
by mseepgood on Thursday October 28, 2021 @03:07AM
(#29023263)
The hybrid approach is absolutely implemented: https://github.com/golang/go/blob/master/src/cmd/compile/int...