Efficiency Hacks - SBCL 1.0.31 User Manual
Description: SBCL 1.0.31 User Manual

Previous: Stale Extensions, Up: Beyond the ANSI Standard

### 7.10 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.

> This function is a no-op on platforms using the generational garbage collector (x86, x86-64, ppc).

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 value-type form

> Specifies that the values returned by `form` conform to the `value-type`, and causes the compiler to trust this information unconditionally.

> Consequences are undefined if any result is not of the declared type `--` typical symptoms including memory corruptions. Use with great care.

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.