perennial: design

perennial@0.1.0Updated 1 min readView as markdown

perennial is a set of persistent (immutable, structurally shared) collections for Rust — HashMap, HashSet, OrdMap, OrdSet and Vector — whose public interface is a drop-in replacement for im-rc 15.1.0 and im 15.1.0, with the additions of imbl 7.0.2. It is an independent implementation written from a clean-room behavioural specification (docs/spec/) and the published algorithm literature; see NOTICE.

Chapters

  1. The interface perennial matches: crates and migration lines, shape decisions, and every place where the references disagree or are defective, with the choice made and why.
  2. Architecture: crates, the pointer-kind abstraction, copy on write by ownership, SBIO layering, the unsafe policy, the module map.
  3. Where the speed comes from: a black-box probe of the references first, then the mechanism and the predicted gain per collection, and the honest limits.
  4. Safety and the known bug classes: one negative test per advisory, panic safety by construction, iterative drop, fuzzing.
  5. Proof plan: differential model tests against imbl, im/im-rc and std; cargo's own test suite with perennial-rc in place of im-rc; compile-level API checks.
  6. Benchmark method: contenders, workloads, harness and outputs.

Behaviour differences, item by item: COMPAT.md.

Decisions in one place

  • Reference versions: im-rc 15.1.0, im 15.1.0, imbl 7.0.2; rpds 1.2.1 and std are measured alongside.
  • Two crates: perennial (Arc, im paths) and perennial-rc (Rc, im-rc paths); both are aliases over generic types parameterised by a pointer kind.
  • #![forbid(unsafe_code)]; no I/O; no_std + alloc with the std feature on by default (it supplies RandomState).
  • OrdMap/OrdSet: B+tree; HashMap/HashSet: CHAMP-style HAMT; Vector: RRB tree with head/tail buffers and a cached focus. Mutation edits uniquely owned nodes in place.
  • Where im 15.1 and imbl 7 disagree, chapter 1's table decides; every such row has a test.