---
title: "perennial: a drop-in replacement for im and im-rc 15.1"
description: "Persistent collections for Rust: HashMap, HashSet, OrdMap, OrdSet and an RRB Vector with O(1) clone and structural sharing. API-compatible with im 15.1 (Arc…"
canonical: "https://perennial.avarok.net/"
lastmod: "2026-12-02T01:52:06Z"
tokens: 5138
---

v0.1.0 on crates.ioMIT OR Apache-2.0

# A drop-in for im-rc. Vector concat 28.7× faster than imbl.

Persistent HashMap, HashSet, OrdMap, OrdSet and Vector for Rust with O(1) clone, under the same paths and signatures as im and im-rc 15.1. cargo's own test suite passes with perennial-rc in place of im-rc. MIT OR Apache-2.0, no unsafe.

[Get started](https://perennial.avarok.net/#quick-start)[See the benchmarks](https://perennial.avarok.net/#benchmarks)

Install

`$ cargo add perennial`

```
# Cargo.toml: migrating is one line
 [dependencies]
- im-rc = "15.1"
+ im-rc = { package = "perennial-rc", version = "0.1" }
```

28.7×

faster Vector concat vs imbl

317.0 vs 9.1k ns per append · Arc · n = 100,000

2.6×

faster random index vs im-rc

2.7 vs 7.0 ns per read · Rc · n = 100,000

0 fail

on cargo's own test suite

cargo lib 192 + resolver-tests 93 pass with perennial-rc as im-rc

Benchmarks

## Vector concatenation, 1,000 appends, n = 100,000

Median of 5 runs on an Apple M3 Max. Raw data is committed; the chart is generated from it.

- perennial-rc 0.1.0277.7
- perennial 0.1.0317.0
- imbl 7.0.29.1k
- im-rc 15.1.011.5k
- im 15.1.011.0k

nanoseconds per append, lower is better[bench/results/2026-12-01-apple-m3-max.jsonl](https://github.com/Avarok-Cybersecurity/perennial/blob/HEAD/bench/results/2026-12-01-apple-m3-max.jsonl)

perennial 0.1.0 · README updated 2026-12-01

**Status.** Version 0.1.0, not yet on crates.io.

**What it is.** perennial is a set of persistent (immutable, structurally shared) collections for Rust. Cloning any of them is one reference-count increment; changing a clone copies only the nodes on the path it touches, and a node owned by one handle alone is edited in place. It is a drop-in replacement for [im](https://crates.io/crates/im) and [im-rc](https://crates.io/crates/im-rc) 15.1, and covers the shared API of [imbl](https://crates.io/crates/imbl) 7.

**Why it exists.** im and im-rc are unmaintained (RUSTSEC-2026-0250, RUSTSEC-2026-0248), and sized-chunks, which they are built on, is unmaintained and has an open panic-safety soundness advisory (RUSTSEC-2026-0255). perennial is an independent implementation, written from a behavioural specification and the published algorithms, with no `unsafe` code and no dependency on either.

**How fast.** On an Apple M3 Max at n = 100,000, Vector concatenation is **28.7× faster than imbl 7.0.2 and 41.5× faster than im-rc 15.1.0**, split-and-rejoin 14.3× and 16.2×, and random indexing 2.7× and 2.6×. For cargo's migration from im-rc: HashMap iteration is 8.4× faster, insert 1.3×, remove 1.5× and clone-then-mutate 1.9×, while lookup is 0.86× (slower). Against imbl, HashMap iteration is 1.6× and clone-then-mutate 1.3× faster, but insert (0.76×), lookup (0.64×) and remove (0.77×) are slower. OrdMap is 1.1–1.3× faster than both on insert, lookup and remove and 2.7–3.0× on iteration. Every number is in the tables below and the raw JSON lines.

## Quick start

```toml
[dependencies]
perennial = "0.1"      # Arc, like im
# perennial-rc = "0.1" # Rc, like im-rc
```

```rust
use perennial::{vector, OrdMap, Vector};

let mut v: Vector<u32> = (0..1_000).collect();
let snapshot = v.clone();            // O(1)
v.push_back(1_000);
v.append(snapshot.clone());          // O(log n) concatenation
let (left, right) = v.split_at(500); // O(log n) split
assert_eq!(left.len() + right.len(), 2_001);
assert_eq!(snapshot.len(), 1_000);   // the clone never changes

let mut m = OrdMap::new();
m.insert("b", 2);
let before = m.clone();
m.insert("a", 1);
assert_eq!(before.len(), 1);
assert_eq!(vector![1, 2, 3].iter().sum::<i32>(), 6);
```

## Migrating from im, im-rc or imbl

One line in Cargo.toml; no source change:

```diff
 [dependencies]
- im-rc = "15.1"
+ im-rc = { package = "perennial-rc", version = "0.1" }
```

For im: `im = { package = "perennial", version = "0.1" }`. Every public item of im-rc 15.1 maps to a row in [docs/COMPAT.md](https://perennial.avarok.net/docs/compat/). The deliberate differences, each with its own test, are in [docs/design/01-interface.md](https://perennial.avarok.net/docs/design/01-interface/); the ones a caller can notice:

|                                        | im / im-rc 15.1             | perennial                                                     |
| -------------------------------------- | --------------------------- | ------------------------------------------------------------- |
| `union` of maps                        | the larger map's values win | `self`'s values win, as the documentation of im and imbl says |
| `Hash`/`Ord` of `HashMap`/`HashSet`    | depend on iteration order   | equal collections hash and compare equal                      |
| `OrdMap::range(..).len()`              | the whole map's length      | the range's length                                            |
| `Vector::sort`                         | unstable                    | stable                                                        |
| `Vector::skip`/`truncate` past the end | panic                       | empty / no-op, as `Vec`                                       |
| type parameters                        | covariant (imbl)            | invariant                                                     |
| pools (`pool` feature)                 | pooled allocation           | accepted for compatibility; allocation is unchanged           |

imbl users: the same `Generic*` types, `shared_ptr::{RcK, ArcK}` and the imbl additions (`get_key_value_mut`, `insert_ord_by`, …) exist; see COMPAT for the rest.

## Benchmarks

Each pairing is the same flavour: perennial-rc against im-rc (Rc), perennial against imbl and im (Arc). std is shown for reference: when nothing is shared, std's collections are faster at almost everything. Sizes 1,000 and 1,000,000 are in the raw data; the tables show 100,000.

Machine: Apple M3 Max, 16 cores, 64 GB, Darwin 27.2.0 arm64, rustc 1.100.0 (0ef1bc386 2026-11-09). Each cell is the median of 5 fresh processes; each process reports the median of 5 timed runs after a warm-up. Speed-up is the other crate's time divided by perennial's (above 1× means perennial is faster). Raw data: [`bench/results/2026-12-01-apple-m3-max.jsonl`](https://github.com/Avarok-Cybersecurity/perennial/blob/HEAD/bench/results/2026-12-01-apple-m3-max.jsonl).

### Vector

 ![Vector: ns per operation at n = 100000, as in the table below](https://perennial.avarok.net/assets/bench-vector.svg)

| workload     | perennial-rc 0.1.0 | im-rc 15.1.0 | im-rc ÷ perennial-rc | perennial 0.1.0 | imbl 7.0.2 | imbl ÷ perennial | im 15.1.0 | im ÷ perennial | std     |
| ------------ | ------------------ | ------------ | -------------------- | --------------- | ---------- | ---------------- | --------- | -------------- | ------- |
| concat       | 278 ns             | 11.5 µs      | 41.49×               | 317 ns          | 9.09 µs    | 28.66×           | 11.0 µs   | 34.76×         | 33.8 ns |
| split-join   | 1.39 µs            | 22.4 µs      | 16.17×               | 1.42 µs         | 20.2 µs    | 14.28×           | 23.4 µs   | 16.54×         | 10.7 µs |
| index-seq    | 2.80 ns            | 6.85 ns      | 2.44×                | 2.78 ns         | 5.83 ns    | 2.10×            | 6.86 ns   | 2.47×          | 0.07 ns |
| index-random | 2.72 ns            | 7.00 ns      | 2.57×                | 2.72 ns         | 7.25 ns    | 2.67×            | 7.12 ns   | 2.62×          | 0.66 ns |
| push-back    | 2.28 ns            | 2.98 ns      | 1.31×                | 2.77 ns         | 5.25 ns    | 1.90×            | 4.88 ns   | 1.76×          | 1.53 ns |
| iterate      | 0.15 ns            | 0.87 ns      | 5.74×                | 0.15 ns         | 0.86 ns    | 5.77×            | 0.86 ns   | 5.73×          | 0.08 ns |

### HashMap

 ![HashMap: ns per operation at n = 100000, as in the table below](https://perennial.avarok.net/assets/bench-hashmap.svg)

| workload     | perennial-rc 0.1.0 | im-rc 15.1.0 | im-rc ÷ perennial-rc | perennial 0.1.0 | imbl 7.0.2 | imbl ÷ perennial | im 15.1.0 | im ÷ perennial | std     |
| ------------ | ------------------ | ------------ | -------------------- | --------------- | ---------- | ---------------- | --------- | -------------- | ------- |
| insert       | 68.6 ns            | 89.6 ns      | 1.31×                | 68.1 ns         | 52.1 ns    | 0.76×            | 91.4 ns   | 1.34×          | 36.5 ns |
| lookup       | 27.1 ns            | 23.4 ns      | 0.86×                | 27.1 ns         | 17.3 ns    | 0.64×            | 23.5 ns   | 0.87×          | 9.66 ns |
| remove       | 92.2 ns            | 136 ns       | 1.47×                | 93.5 ns         | 72.5 ns    | 0.77×            | 164 ns    | 1.75×          | 18.5 ns |
| iterate      | 3.94 ns            | 33.1 ns      | 8.41×                | 4.00 ns         | 6.37 ns    | 1.59×            | 35.8 ns   | 8.96×          | 1.33 ns |
| clone-mutate | 777 ns             | 1.47 µs      | 1.89×                | 798 ns          | 1.00 µs    | 1.26×            | 1.50 µs   | 1.88×          | –       |

### OrdMap

 ![OrdMap: ns per operation at n = 100000, as in the table below](https://perennial.avarok.net/assets/bench-ordmap.svg)

| workload     | perennial-rc 0.1.0 | im-rc 15.1.0 | im-rc ÷ perennial-rc | perennial 0.1.0 | imbl 7.0.2 | imbl ÷ perennial | im 15.1.0 | im ÷ perennial | std     |
| ------------ | ------------------ | ------------ | -------------------- | --------------- | ---------- | ---------------- | --------- | -------------- | ------- |
| insert       | 90.6 ns            | 116 ns       | 1.28×                | 91.0 ns         | 108 ns     | 1.19×            | 115 ns    | 1.27×          | 81.2 ns |
| lookup       | 31.9 ns            | 38.6 ns      | 1.21×                | 32.0 ns         | 42.7 ns    | 1.33×            | 38.0 ns   | 1.19×          | 70.0 ns |
| remove       | 101 ns             | 114 ns       | 1.13×                | 100 ns          | 114 ns     | 1.13×            | 117 ns    | 1.16×          | 84.9 ns |
| iterate      | 0.88 ns            | 2.35 ns      | 2.66×                | 0.89 ns         | 2.68 ns    | 3.01×            | 2.35 ns   | 2.63×          | 3.52 ns |
| clone-mutate | 493 ns             | 870 ns       | 1.77×                | 535 ns          | 491 ns     | 0.92×            | 1.08 µs   | 2.02×          | –       |

### Resolver trace (OrdSet + HashMap)

 ![Resolver trace (OrdSet + HashMap): ns per operation at n = 100000, as in the table below](https://perennial.avarok.net/assets/bench-resolver.svg)

| workload  | perennial-rc 0.1.0 | im-rc 15.1.0 | im-rc ÷ perennial-rc | perennial 0.1.0 | imbl 7.0.2 | imbl ÷ perennial | im 15.1.0 | im ÷ perennial | std     |
| --------- | ------------------ | ------------ | -------------------- | --------------- | ---------- | ---------------- | --------- | -------------- | ------- |
| backtrack | 339 ns             | 494 ns       | 1.46×                | 340 ns          | 391 ns     | 1.15×            | 652 ns    | 1.92×          | 15.2 µs |

Workloads: `insert`, `lookup`, `remove` (per key, shuffled u64), `iterate` (per element), `clone-mutate` (per insert: clone, 10 inserts, every version kept alive), `push-back` and `index-*` (per element), `concat` (per append: 1,000 vectors appended in turn), `split-join` (per round: split at a random point and append back, 1,000 rounds), `backtrack` (per step of a resolver-shaped trace: OrdSet priority queue, HashMap activations, a clone of both every 4 steps and a restore every 16). Method: [docs/design/06-bench.md](https://perennial.avarok.net/docs/design/06-bench/). Reproduce: `node bench/drive.mjs`.

## Compatibility

- Rust 1.85 or newer for the library with every feature except `proptest` (its dependency needs 1.88); the test suite needs a current stable.
- `no_std` + `alloc` with `default-features = false` (then `HashMap`/`HashSet` need an explicit hasher). Builds for `wasm32-unknown-unknown` and `thumbv7em-none-eabi` in CI.
- Features: `serde`, `proptest`, `quickcheck`, `arbitrary`, `rayon` (perennial only), `debug`, `pool` (alias `refpool`).
- Item by item: [docs/COMPAT.md](https://perennial.avarok.net/docs/compat/), which also compares perennial with im, imbl and rpds.

## Questions people ask

### Is perennial a drop-in replacement for im-rc?

Yes for code using im-rc 15.1's public API: rename the dependency (above). cargo's own library and resolver test suites pass unchanged with perennial-rc in place of im-rc, in CI on every change. The behaviour differences are listed above and in COMPAT.

### Is perennial faster than im, im-rc and imbl?

For Vector, yes by a wide margin: concatenation is 28.7× faster than imbl and 41.5× faster than im-rc, split-and-rejoin 14×–16× and indexing about 2.6×. OrdMap is 1.1×–3× faster on every operation except clone-then-mutate against imbl (a tie). HashMap is faster than im-rc except on lookup, and slower than imbl on insert, lookup and remove. The numbers are in [Benchmarks](https://perennial.avarok.net/#benchmarks).

### Can I use it in a commercial or closed-source project?

Yes, because perennial is licensed MIT OR Apache-2.0 at your option. It depends on no copyleft crate, so nothing in its dependency tree places obligations on your own code.

### How do I migrate from im?

Change `im = "15.1"` to `im = { package = "perennial", version = "0.1" }` in Cargo.toml. For im-rc, rename it to `perennial-rc` the same way; no `use` line or call site in your code has to change.

### Does it fix the im and sized-chunks advisories?

It shares no code with im, im-rc or sized-chunks, so their unsound code paths are not present. The bug classes are still tested: an OrdSet of Strings (RUSTSEC-2023-0126) and panicking `Clone`/`Ord`/`Hash`/`Drop` elements during every mutation (RUSTSEC-2026-0255) run under Miri in CI.

### Why not std's collections?

Use std's collections when nothing is shared, because they are faster per operation. Persistent collections pay off when you keep many versions, clone often, undo changes or share data across threads.

## License

Licensed under either of [Apache License, Version 2.0](https://github.com/Avarok-Cybersecurity/perennial/blob/HEAD/LICENSE-APACHE) or [MIT license](https://github.com/Avarok-Cybersecurity/perennial/blob/HEAD/LICENSE-MIT) at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in perennial by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. See [NOTICE](https://github.com/Avarok-Cybersecurity/perennial/blob/HEAD/NOTICE) for how it was written, [CONTRIBUTING.md](https://github.com/Avarok-Cybersecurity/perennial/blob/HEAD/CONTRIBUTING.md) (clean-room rules apply) and [SECURITY.md](https://github.com/Avarok-Cybersecurity/perennial/blob/HEAD/SECURITY.md) for private reports.

## How it works

- **Vector**: an RRB tree (relaxed radix balanced, branching 64) with a head buffer and a tail leaf, size tables only on nodes a concat or split made uneven, O(log n) concat and split, and a focus that caches the current leaf for sequential access.
- **OrdMap / OrdSet**: a B+tree (leaves of 64, branches of 32) whose children carry their entry counts, so rank, `range(..).len()` and neighbours are O(log n).
- **HashMap / HashSet**: a CHAMP trie with two 32-bit bitmaps per node, the full hash stored with each entry and a canonical shape after removal.
- **Copy on write by ownership**: every edit goes through `make_mut`, so a node owned by one handle is edited in place and a shared node is copied once.

Design notes: [docs/DESIGN.md](https://perennial.avarok.net/docs/design/).

## What this does not prove

- **HashMap against imbl.** imbl 7.0.2 is faster at insert (1.31×), lookup (1.57×) and remove (1.29×) at n = 100,000, and lookup is also slower than im-rc (0.86×). perennial wins on iteration and clone-then-mutate only.
- **OrdMap clone-then-mutate against imbl** is a tie (0.92× at 100,000, 0.97× at 1,000, 1.03× at 1,000,000).
- **std is faster** whenever no version is kept: `Vec::append` copies 100,000 elements in 34 ns per append, and std's HashMap lookup is 2.8× faster.
- **One machine.** Every number comes from one Apple M3 Max; other CPUs and allocators will move them. The resolver trace is a synthetic workload shaped like cargo's resolver, not cargo itself.
- **Not covered:** memory use per element, `Arc` contention across threads, and the im-rc/imbl inline-storage optimisation for small collections (perennial has none).
- **Compatibility** is proven by cargo's test suite, the 582-row COMPAT table and differential tests against imbl, im-rc and `std`; a crate that depends on unspecified behaviour (iteration order of `HashMap`, the deliberate differences above) can still notice the change.

```json
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@id": "https://thomaspbraun.com/#person",
      "@type": "Person",
      "name": "Thomas Braun",
      "sameAs": [
        "https://github.com/tbraun96",
        "https://x.com/tbraun96"
      ],
      "url": "https://thomaspbraun.com",
      "worksFor": {
        "@id": "https://avarok.net/#organization"
      }
    },
    {
      "@id": "https://avarok.net/#organization",
      "@type": "Organization",
      "name": "Avarok",
      "url": "https://avarok.net"
    },
    {
      "@id": "https://perennial.avarok.net/#website",
      "@type": "WebSite",
      "inLanguage": "en",
      "name": "perennial",
      "publisher": {
        "@id": "https://thomaspbraun.com/#person"
      },
      "url": "https://perennial.avarok.net/"
    },
    {
      "@id": "https://perennial.avarok.net/",
      "@type": "WebPage",
      "about": {
        "@id": "https://perennial.avarok.net/#software"
      },
      "author": {
        "@id": "https://thomaspbraun.com/#person"
      },
      "dateModified": "2026-12-01",
      "description": "Persistent collections for Rust: HashMap, HashSet, OrdMap, OrdSet and an RRB Vector with O(1) clone and structural sharing. API-compatible with im 15.1 (Arc…",
      "inLanguage": "en",
      "isPartOf": {
        "@id": "https://perennial.avarok.net/#website"
      },
      "name": "perennial",
      "url": "https://perennial.avarok.net/"
    },
    {
      "@id": "https://perennial.avarok.net/#source",
      "@type": "SoftwareSourceCode",
      "author": {
        "@id": "https://thomaspbraun.com/#person"
      },
      "codeRepository": "https://github.com/Avarok-Cybersecurity/perennial",
      "description": "Persistent collections for Rust: HashMap, HashSet, OrdMap, OrdSet and an RRB Vector with O(1) clone and structural sharing. API-compatible with im 15.1 (Arc flavour).",
      "keywords": "persistent, immutable, data-structures, hamt, rrb",
      "license": [
        "https://opensource.org/licenses/MIT",
        "https://www.apache.org/licenses/LICENSE-2.0"
      ],
      "maintainer": {
        "@id": "https://thomaspbraun.com/#person"
      },
      "name": "perennial",
      "programmingLanguage": [
        "Rust"
      ],
      "runtimePlatform": "Rust 1.85",
      "sourceOrganization": {
        "@id": "https://avarok.net/#organization"
      },
      "targetProduct": {
        "@id": "https://perennial.avarok.net/#software"
      },
      "version": "0.1.0"
    },
    {
      "@id": "https://perennial.avarok.net/#software",
      "@type": "SoftwareApplication",
      "alternateName": "perennial",
      "applicationCategory": "DeveloperApplication",
      "applicationSubCategory": "Rust library",
      "author": {
        "@id": "https://thomaspbraun.com/#person"
      },
      "description": "Persistent collections for Rust: HashMap, HashSet, OrdMap, OrdSet and an RRB Vector with O(1) clone and structural sharing. API-compatible with im 15.1 (Arc flavour).",
      "downloadUrl": "https://crates.io/crates/perennial",
      "isAccessibleForFree": true,
      "license": [
        "https://opensource.org/licenses/MIT",
        "https://www.apache.org/licenses/LICENSE-2.0"
      ],
      "name": "perennial",
      "offers": {
        "@type": "Offer",
        "price": "0",
        "priceCurrency": "USD"
      },
      "operatingSystem": "Rust 1.85",
      "publisher": {
        "@id": "https://avarok.net/#organization"
      },
      "softwareVersion": "0.1.0",
      "url": "https://perennial.avarok.net/"
    }
  ]
}
```
