3 ms·
Can anyone explain to me why he got better performance with GC turned on (and optimised) rather than off?
by dm319 9y ago
Can anyone explain to me why he got better performance with GC turned on (and optimised) rather than off?
- tom_mellior 9y agoJudicious garbage collection reuses memory you have already allocated, and for which there may already be entries in caches, page tables, garbage collector metadata, and whatnot. If you never garbage collect, the runtime has to repeatedly allocate new memory from the operating system, and all this additional metadata has to be juggled. If allocating new memory is a system call, that has costs. If you get lots of page faults because you keep using new pages, that has costs as well.
- emeraldd 9y agoIt sounds like instead of turning off GC, the algorithm was changed to an "automatic" allocation/deallocation scheme that's closer to what you might see with manual memory management in a C like world. I wonder if the Go runtime has any optimizations to turn things into stack/static allocations in that scenario.
- tom_mellior 9y agoI'm not a Go expert, but my understanding of the blog was that the algorithm or any other aspect of the code was not changed. Only the garbage collection frequency.
- emeraldd 9y agoMy comment was in reply to the parent's: > If you never garbage collect, the runtime has to repeatedly allocate new memory from the operating system ...
- tom_mellior 9y agoYeah, that was me. I still don't understand what you're saying. Who is changing what algorithm in what component? If you tell the Go runtime not to garbage collect but keep allocating memory, that memory has to come from somewhere. That somewhere is the operating system.