Hacker News new | ask | show | jobs
by rustnote 1693 days ago
So there's a runtime cost for using generics?
2 comments

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.

The hybrid approach is absolutely implemented: https://github.com/golang/go/blob/master/src/cmd/compile/int...
Yes, the same cost as calling a method through an interface. IIUC, the concrete implementation can change.
No, it does not have the same cost as calling a method through an interface.