KCL's interpreter faced performance issues from copying entire program memory when defining functions (closures). Two solutions were implemented: first, a copy-on-write snapshot mechanism that makes creating snapshots O(1) instead of O(n); second, an epoch counter system inspired by MVCC that tracks value creation time and handles mutation only where needed. Both approaches preserve closure semantics (capturing environment at definition time) while dramatically improving memory efficiency and execution speed. The epoch solution simplified the codebase and enables future optimizations like references in program memory.
Table of contents
Background - how KCL program memory worksFirst iteration - snapshots| snapshot | a | b | c | d |Second iteration - epochsSort: