by coder543 · 4y ago · 0 comments
As long as the global slice is never mutated, the current approach is probably fine, but it is definitely a semantic change to the code.
I’m also fairly sure Go uses RVO here too, which cuts down on the number of times the object is copied around, but again, it’s irrelevant to the discussion of heap allocations. Copying the object isn’t the performance problem here, needlessly allocating a very short-lived object on the heap over and over is.