[plt-scheme] Some thoughts about GC and realtime aplications
(For the original commenter: I would be somewhat surprised if people
writing truly performance-critical apps are using malloc()/free().
Libc's malloc() and free() are not particularly cheap, you see. I
strongly suspect that they allocate large chunks from the OS and then
write their own, custom allocators/deallocators. Obviously, you could
do the same with a collector, as long as you can mutate objects and
you're careful about clearing references out before returning dead
objects to the pool.)
On May 19, 2006, at 12:23 PM, John Clements wrote:
> One mistake here: don't confuse "uses lots of ram" with "runs
> slowly". In fact, the _opposite_ can be true; that is, in a gc
> system you may be trading compactness for speed.
This is less true now than it was 10 years ago. Futzing with various
modifications of newgc.c has taught me that it's surprisingly easy to
make a machine's caches and TLB fall down and die. Basically, a
garbage collection pretty much destroys the L1 and L2 cache, and it's
very important not to add insult to this injury. Or, another way of
putting this: pure copying collectors are very fast except in the
real world. In the real world, your very streamlined copying
collector is going to spend all its time waiting on cache misses,
burning out the TLB, and twiddling its thumbs while the OS
desperately tries to map memory for it.
On the bright side, collectors can compact the heap during collection
so that the caches/TLB/VM are more effective post-collection.
Finally, outside of game programming (of which I have no knowledge or
interest), there is no such thing as a single program running on a
machine any more. Most of the time, I have 3/4ths of the applications
on my Dock running at any time, and that doesn't count all the
various daemons, widgets and system apps running. So it's very, very,
very important for the collector to give as much memory back to the
OS as it can, so the GCed app doesn't make the OS's virtual memory
system give up and take a nice vacation in the Bahamas.
-Adam