3 ms·
GC Shape Stenciling, a hybrid of stenciling and dictionaries: https://go.googlesource.com/proposal/+/refs/heads/master/design/generics-implementation-gcshape.md
by mseepgood 5y ago
GC Shape Stenciling, a hybrid of stenciling and dictionaries: https://go.googlesource.com/proposal/+/refs/heads/master/design/generics-implementation-gcshape.md https://go.googlesource.com/proposal/+/refs/heads/master/des...
- rustnote 5y agoSo there's a runtime cost for using generics?
- wwarner 5y agoYes, the same cost as calling a method through an interface. IIUC, the concrete implementation can change.
- mseepgood 5y agoNo, it does not have the same cost as calling a method through an interface.
- Kranar 5y agoThe 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.
- arc619 5y ago> 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.
- mseepgood 5y agoThe hybrid approach is absolutely implemented: https://github.com/golang/go/blob/master/src/cmd/compile/internal/noder/stencil.go https://github.com/golang/go/blob/master/src/cmd/compile/int...
- Zababa 5y agoHow 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.
- mseepgood 5y agoThe 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.