Re:Show HN: Mmm – manual memory management for Go
by tptacek on Monday November 30, 2015 @12:34PM
(#10650589)
Nitpick: they're fine in otherwise-reasonable code as long as they aren't shredding the cache. But there are lots of unreasonable designs that waste tons of space, further burning up locality even when the pointers aren't traversed, that are due to pointer overuse.
Re:Show HN: Mmm – manual memory management for Go
by pcwalton on Monday November 30, 2015 @12:39PM
(#10650613)
Yes, definitely true; sizeof(void *) and malloc slop aren't free.
The parenthetical is important. Pointers are just fine as long as you don't dereference them and suffer cache misses as a result.
It's also worthwhile to note that what you described is not always a worthwhile optimization, even if you can do it. If, for example, you traverse an array of the objects containing a sub-object frequently and follow the pointer to that object only rarely, it's often worthwhile to allocate it separately to improve cache locality of that traversal. This is even more important if you're doing a lot of structure copies of the outer structure; avoiding copying more bits saves a lot of time. The latter case comes up surprisingly often in my experience, and I've improved performance of code quite a few times with separate allocations and pointer indirection.