Hasty Briefsbeta

Bilingual

The Manchester Garbage Collector and purple-garden's runtime

4 months ago
  • #scripting-language
  • #garbage-collection
  • #performance
  • The Manchester Garbage Collector (mgc) is designed for the purple-garden runtime, combining multiple garbage collection techniques for improved performance.
  • Purple-garden is a minimalist scripting language focused on performance, low memory footprint, and embeddability, implemented in C as a register-based bytecode compiler and virtual machine.
  • The mgc uses a composite approach: allocation into preallocated memory regions, reachability analysis via recursive root set tracing, and compacting semi-space copying.
  • Key features of mgc include fast allocation, low allocation latency, and reduced fragmentation.
  • The garbage collection process in mgc is divided into three stages: Mark Phase, Copy Phase, and Reset/Swap Phase.
  • The root set for garbage collection in purple-garden includes VM registers and the variable table holding local variable bindings.
  • Values in purple-garden are designed with minimal overhead, using bit tags for type and optionality, enabling zero-allocation optional values.
  • The runtime uses a growing bump allocator to minimize syscalls and improve allocation performance.
  • Strings in purple-garden are abstracted with a length and hash, avoiding the pitfalls of C-style strings.
  • Garbage collection is triggered based on memory usage thresholds, checked after leaving a scope to minimize latency.
  • The mgc avoids complex features like generational collection or reference counting, focusing on simplicity and performance for short-lived scripts.
  • The design includes invariants and assumptions critical for correct operation, such as register discipline and heap allocation markers.
  • A Rust rewrite of purple-garden is underway to leverage Rust's abstractions, error handling, and collections for improved maintainability and performance.