Hacker News new | ask | show | jobs
by masklinn 1615 days ago
> With generics you get a performance boost from annihilating the run-time overhead. Yes?

I don't know whether creating an interface{} has a runtime cost (though it may if the type pointer has to be looked up at runtime?), however there's also a memory overhead: I didn't look at everything but the first two benches (pushfront and pushbach) use `int` values, which are 32 bits. But interface{} is 2 words (128 bits).

This quadruples the memory requirements, meaning the backing buffer may well need either more reallocations, or to make larger allocations & have to span multiple cache lines.

1 comments

I think you’re on to something. Just reread this article: https://blog.gopheracademy.com/advent-2018/interfaces-and-re... And there’s definitely an overhead associated with the interface type due to run-time reflection. I guess generics does away with this.