Previous: Stale Extensions, Up: Beyond the ANSI Standard


6.8 Efficiency Hacks

The sb-ext:purify function causes SBCL first to collect all garbage, then to mark all uncollected objects as permanent, never again attempting to collect them as garbage. This can cause a large increase in efficiency when using a primitive garbage collector, or a more moderate increase in efficiency when using a more sophisticated garbage collector which is well suited to the program's memory usage pattern. It also allows permanent code to be frozen at fixed addresses, a precondition for using copy-on-write to share code between multiple Lisp processes. This is less important with modern generational garbage collectors, but not all SBCL platforms use such a garbage collector.

— Function: sb-ext:purify &key root-structures environment-name

This function optimizes garbage collection by moving all currently live objects into non-collected storage. root-structures is an optional list of objects which should be copied first to maximize locality.

defstruct structures defined with the (:PURE T) option are moved into read-only storage, further reducing gc cost. List and vector slots of pure structures are also moved into read-only storage.

environment-name is gratuitous documentation for compacted version of the current global environment (as seen in sb!c::*info-environment*.) If nil is supplied, then environment compaction is inhibited.

The sb-ext:truly-the special form declares the type of the result of the operations, producing its argument; the declaration is not checked. In short: don't use it.

— Special Operator: sb-ext:truly-the type value

The sb-ext:freeze-type declaration declares that a type will never change, which can make type testing (typep, etc.) more efficient for structure types.

The sb-ext:constant-function declaration specifies that a function will always return the same value for the same arguments, which may allow the compiler to optimize calls to it. This is appropriate for functions like sqrt, but is not appropriate for functions like aref, which can change their return values when the underlying data are changed.