$ show mirage/irmin
Irmin is an OCaml library and ecosystem for building mergeable, branchable, version-controlled key-value stores inspired by Git's data model. It provides a core set of abstractions (content-addressable storage, atomic writes, indexed stores, tree-like nodes, merge combinators, watches, sync protocols) along with multiple backends: in-memory, filesystem, Git (bidirectional), and a custom on-disk pack format optimized for blockchain use cases (Tezos). The project includes a full CLI tool (`irmin`), a GraphQL server, a TCP/WebSocket client-server protocol, MirageOS support, C bindings, and a PPX deriver for automatic type representation. The architecture is heavily functor-based, enabling compositional reuse. The pack backend (`irmin-pack`) is a significant piece of engineering with garbage collection, incremental indexing, chunked suffix files, sparse file abstraction, versioned disk formats (V1–V5), and migration support. The codebase is well-tested with extensive integration and unit tests, and includes benchmarks for Tezos history replay and inode performance. The primary risk is the complexity of maintaining multiple backends and on-disk format versions, with some modules containing TODO comments or `assert false` placeholders.
The LLM identified 4 files worth highlighting for reuse:
A generic LRU (Least Recently Used) cache implemented as a functor `Lru.Make(K)(V)` that provides a type-safe, bounded-size cache with `find`, `add`, `clear`, and `mem` operations. It is self-contained (no internal module dependencies) and can be extracted for any OCaml project requiring a bounded cache with configurable capacity and value size tracking. The implementation uses a double-linked list and hash table, and is the basis for caches in the pack backend and inode store.
A generic notification/watch system implemented as a functor `Watch.Make(K)(V)` that provides key-based and global watch callbacks, list-dir watches, and unsubscribe support. It is independent of the rest of Irmin and can be reused in any OCaml project requiring push-based change notifications with typed keys and values. The module handles concurrency with Lwt mutexes and delivers callbacks asynchronously.
A library of merge combinators for three-way merging of OCaml values, including `default` (right-biased), `idempotent` (same value wins), `option`, `list` (set-based), `map`, `counter` (CRDT-style), and custom `like` adapters. It is standalone and can be extracted for any application needing composable, conflict-aware merge logic. The implementation uses a `Merge.result` type with conflicts, and provides `alist` for associative lists with default merge on values. It is used throughout Irmin for node and contents merging.
An efficient hash set for fixed-size strings backed by OCaml Bigarrays, providing `create`, `add`, `mem`, `remove`, and iteration operations. It is designed for keys of a fixed byte length (e.g., 32-byte hashes) and uses open addressing with Robin Hood hashing. The module is self-contained (depends only on Bigarray and Stdlib) and can be reused in any OCaml project requiring a compact, high-performance set of fixed-length keys. Benchmark code compares it favorably against the stdlib `Hashtbl` in both memory and speed.