3 ms·
I would have to imagine that at runtime there is no difference between a generic and non-generic function. I imagine (emphasis on imagine: no actually knowledge
by dmitryminkovsky 4y ago
I would have to imagine that at runtime there is no difference between a generic and non-generic function. I imagine (emphasis on imagine: no actually knowledge) that generics are used at compile time to check types? I have no idea whether Go erases generics though. Maybe introspection is slower with them?
- gmfawcett 4y agoWorth reading: https://go.dev/blog/when-generics https://go.dev/blog/when-generics
- throwaway894345 4y agoGo's generic implementation (sadly) tries to reduce the amount of code it generates by generating code which dispatches to the concrete methods at runtime. The rules for when this dispatch happens aren't easy to understand, and they're subject to change, so reasoning about performance (already hard) gets strictly harder. In some cases, generics might make code faster, and in others it may make code slower.
- throwawaymaths 4y agoThere is a difference. Most people (who use go for network IO bound services) will not notice.