AI Glossary / MLOps and deployment / Intermediate
CDR coding
Definition
CDR coding is a technique for reducing the memory occupied by Lisp list cells. It replaces some explicit pointers to the rest of a list with compact tags meaning, for example, “the next cell follows here” or “this list ends.”
What it means
In Lisp, a cons cell normally contains two components. CAR identifies its first component; CDR identifies its second. A conventional list uses the CDR to refer to the remaining list, ending with NIL. The first component may itself refer to a complex object.
When successive list cells occupy adjacent memory locations, storing their full next-cell addresses can be redundant. CDR coding records that adjacency instead. A decoder can calculate where the next cell is rather than fetching a separately stored pointer.
This is a representation technique for data structures, not a method of shortening written Lisp expressions. It also differs from compressing a saved file. The representation must support the language's operations on live objects, including shared references and changes to list structure. Lisp has a historical role in symbolic AI.
How it works
An implementation associates a small code with a cell. A normal form provides an explicit CDR, a next form indicates an adjacent cell, and a NIL form indicates termination. Exact codes and layouts depend on the machine or runtime; these names describe the idea rather than a universal binary standard.
Building an entire list together makes adjacent allocation straightforward. Building it through unrelated allocations does not guarantee that arrangement. A garbage collector that relocates objects can sometimes bring successive cells together and recover compact representations.
Mutation is the difficult case. If a next-coded cell must point somewhere else, its current layout may lack room for the new pointer. An extension or forwarding arrangement can supply the missing storage while preserving references to the original object. The runtime must make ordinary CAR and CDR operations follow that arrangement correctly. Space savings therefore come with tag interpretation, mutation handling and memory-management complexity.
Three practical examples
- A symbolic expression evaluator stores many short, immutable lists compactly when their elements are allocated together.
- A runtime designer compares explicit-pointer cells with compact cells under a workload containing frequent changes to list tails.
- A garbage-collector experiment measures whether arranging successive list cells together reduces live memory enough to justify additional collection work.
Think of it this way
Think of a walking itinerary. Instead of printing the address of every next stop, it can sometimes say “the next doorway.” At the end it says “finished.” A full address remains necessary when the route jumps elsewhere.
The analogy explains why adjacency can replace an address. It does not make a list a physical street: software can share tails, change links and relocate objects. Preserving those behaviors is part of the implementation problem.
Worked example
Counting cell storage under explicit assumptions
Consider the list A, B, C. In a teaching layout, an ordinary cons cell occupies two 32-bit words, one for each component. Three cells therefore occupy six words, or 24 bytes.
Suppose a compact layout stores each first component and its tag in one 32-bit word, with cells at successive word addresses 100, 101 and 102. The first two carry NEXT tags; the last carries NIL. Cell storage becomes three words, or 12 bytes: a 50% reduction for these cells.
That calculation excludes the objects represented by A, B and C, allocator headers and other runtime costs. It assumes the tags fit in the stated word layout. Application memory need not halve.
Now change the tail at address 101 to refer to another list. The runtime cannot simply treat address 102 as that new tail. It needs an explicit-pointer or extension representation. That extra storage reduces the original saving, while preserving the meaning of existing references.
Illustrative case study
A fictional team maintaining a symbolic planning engine investigates a memory problem. Most planning descriptions are constructed once and then read repeatedly, but temporary search lists are frequently modified.
The team models compact storage separately for these two populations. Read-mostly lists appear promising because allocation and collection can preserve adjacency. Temporary lists require more fallback cells and additional pointer chasing after mutations.
The team does not report the ideal cell saving as a measured whole-system improvement. It records live memory, collection pauses and traversal cost on representative workloads before choosing a design. This invented case illustrates why the structure's usage pattern matters as much as its compact initial layout.
Common misconceptions and mistakes
- CDR coding does not require every tail to point to an adjacent cell; less compact forms handle other cases.
- A cons cell's second component need not always be a conventional list tail.
- Saving pointer slots does not eliminate tags, headers or garbage-collection overhead.
- Changing a compact cell must preserve shared references and language semantics.
- A historical machine's tag meanings should not be assumed for every implementation.
Business use
CDR coding helps explain why runtimes can use different amounts of memory for the same logical structure.
For teams implementing symbolic AI infrastructure, it provides a concrete design tradeoff: compact common cases versus more complex exceptional operations. Evaluate memory and execution costs together, especially where predictable response times matter. Ask whether observed savings come from cell representation, object sharing or a changed allocation policy; these mechanisms should not be confused.
People also ask
Is CDR coding lossless?
It is intended to preserve the logical cons structure and its supported operations. Correctness depends on the implementation maintaining those semantics.
Does it compress the values stored in the list?
Not necessarily. Its central saving concerns how links between cells are represented; referenced objects can remain unchanged.
Does it require specialized hardware?
Hardware can support its operations, but the representation idea can also be implemented in software. Performance depends on the chosen runtime design.
Check your understanding
A compact representation halves the space occupied by cons cells, but those cells account for only one quarter of an application's memory. Ignoring other changes, what is the overall saving?
Answer: One half of one quarter is one eighth, or 12.5%. Other objects remain, and added runtime overhead could reduce that saving.
Related terms
- cons cell
- CAR
- CDR
- linked list
- pointer
- garbage collection
- object identity
- symbolic AI
Learn next
Draw two lists sharing the same final cell. Change one earlier tail and trace which references must remain valid. Then compare how an explicit-pointer layout and a compact layout could implement that operation.
More in MLOps and deployment
- Brotli - Brotli is a general-purpose lossless compression format and algorithm family for representing data in fewer bytes when its patterns permit.
- Burrows - Wheeler transform - The Burrows - Wheeler transform (BWT) is a reversible rearrangement of a block of symbols that can make the block easier to compress.
- Canonical Huffman code - A canonical Huffman code is a Huffman-style prefix code whose bit patterns are assigned by a fixed ordering rule once each symbol's code length is known.
- Checkpoint - A checkpoint is a saved representation of a computation's state at a particular point.
- Checkpointing - Checkpointing is the process of saving a computation's recoverable state at selected points so that work can resume after interruption.
- Chroma subsampling - Chroma subsampling reduces the spatial resolution of an image's color-difference components while retaining a more detailed luma component.
Sources
Sources: Henry G. Baker Jr., Actor Systems for Real-Time Computation, MIT/LCS/TR-197, section 4.5: https://bitsavers.trailing-edge.com/pdf/mit/lcs/tr/MIT-LCS-TR-0197.pdf . The CDR representation and mutation discussion were reviewed. The storage calculation is an original simplified example, not a measurement of the thesis's implementation.
Previous: Caverphone Next: Cell