Lisp HUG Maillist Archive

Re: Tuning GC

At the risk of stating the obvious,
tuning a lisp session for minimal GC really has two aspects.  How you use
memory and how the system cleans up after you.

Clearly, generating less garbage is a Good Thing.  Simply reusing a large
array rather than allocating a new one each time you need it can have a
huge effect on execution speeds (> X10, which includes time for GC).
Similarly for consing up lists unnecessarily, but coding for minimal
consing is a fine art and requires some knowledge of the particular
implementation you are working with.

With objects the same concepts apply.  If you are generating a large number
of objects and throwing them away, you might want to consider a pool of
them that you reuse.  You could put the pool on an :allocation :class
variable.   Although many lisps have fairly efficient implementations of
CLOS, generating an instance and initializing it is still somewhat
expensive, and you will pay the GC costs as well.

Most Lisp implementations have fairly intelligent GC strategies right out
of the box, so tuning them may not buy you much.

From personal experience, trying to tune the garbage collector generally
bought me a factor of 2 in performance, while doing some fairly trivial
memory management in my program (at the cost of about a dozen lines of
code) bought me a factor of greater than 10.  YMMV.

Ray Laning


Updated at: 2020-12-10 09:02 UTC