2 ms·
Generics absolutely (can) make things faster, if the collection is generic in the first place: the lack of generics would require RTTI and possibly boxing, the
by masklinn 5y ago
Generics absolutely (can) make things faster, if the collection is generic in the first place: the lack of generics would require RTTI and possibly boxing, the article specifically mentions the use of `interface{}` so that seems overwhelmingly likely.
Hell the first benchmark just pushes a bunch of `int` onto the stack, with generics it just does that, without it has to pack the int into an interface{} quadrupling its size. The performance difference may well just come from the increase in allocations (and reallocation), and cache pressure, that sort of things. Nothing complicated, really.
> missed optimization in the compiler.
Go's compiler is pretty simplistic and not a heavily optimising one, so it'd also be unsurprising if type erasure also hindered it.