3 ms·
> Another approach I've used with caches in Go is to just use a huge byte slice as the cache without any pointers, so the GC can ignore it. Just to check that
by Jtsummers 6y ago
> Another approach I've used with caches in Go is to just use a huge byte slice as the cache without any pointers, so the GC can ignore it.
Just to check that I understand what you're suggesting here, this is comparable to how we embedded systems folks might pre-allocate (either statically or at the very start of a program execution) a large chunk of memory and use it instead of using traditional malloc/free (or language equivalent), correct? So you bypass the GC and avoid any potential performance penalties introduced by having a smaller number of massive allocations that never get moved, freed, or reallocated.
- jeffbee 6y agoYes, the idea is similar. If you make a huge map in Go with millions of items, it will stress the GC. If you take the same information and just put it into a big byte slice, and index into it in a way that the GC doesn't think you're pointing to addresses, then it will be much faster. Of course now you are writing a little more code.