3 ms·
It will if it means that the compiler can generate code which uses static dispatch rather than dynamic dispatch - it can be an improvement over using interface{
by captainbland 5y ago
It will if it means that the compiler can generate code which uses static dispatch rather than dynamic dispatch - it can be an improvement over using interface{} which I understand is the common way of dealing with cases that need generic behaviour in Go (with alternatives being code generation and simply copy-pasting).
As far as I understand, with interface{} the compiler can't just decide to generate static dispatch based code because there's not enough information to generate that in a generalisable way (the code can depend on information that is only available at run-time rather than compile-time) and it would be bad for programmers who expect dynamic dispatch to be used because they're optimising for something else e.g. binary size or compilation speed.
Obviously generics wouldn't be a performance improvement over using, say, code generation or doing a bunch of copy-pasting (and, given Go's lack of function overloading, a bunch of annoying renaming and some logic to dispatch to those methods which actually might cause more of a performance hit...) but those approaches tend to cause other problems.