v0.1.0 on crates.ioMIT OR Apache-2.0
A drop-in replacement for im-rc, with Vector concatenation 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.
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.
nanoseconds per append, lower is betterbench/results/2026-12-01-apple-m3-max.jsonl
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 and im-rc 15.1, and covers the shared API of 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
[dependencies]
perennial = "0.1" # Arc, like im
# perennial-rc = "0.1" # Rc, like im-rc
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:
[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. The deliberate differences, each with its own test, are in
docs/design/01-interface.md; 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.
Vector
| 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
| 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
| 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)
| 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. 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+allocwithdefault-features = false(thenHashMap/HashSetneed an explicit hasher). Builds forwasm32-unknown-unknownandthumbv7em-none-eabiin CI.- Features:
serde,proptest,quickcheck,arbitrary,rayon(perennial only),debug,pool(aliasrefpool). - Item by item: docs/COMPAT.md, 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.
Can I use it in a commercial or closed-source project?
Yes. It is MIT OR Apache-2.0, at your option, and depends on nothing copyleft.
How do I migrate from im?
Change im = "15.1" to im = { package = "perennial", version = "0.1" }. For im-rc use
perennial-rc.
Does it fix the im and sized-chunks advisories?
It shares no code with them. The bug classes are tested: an OrdSet
of Strings (RUSTSEC-2023-0126) and panicking Clone/Ord/Hash/Drop elements during mutation (RUSTSEC-2026-0255)
run under Miri in CI.
Why not std's collections?
Use them when nothing is shared: they are faster. Persistent collections pay off when you keep many versions, clone often or share across threads.
License
Licensed under either of Apache License, Version 2.0 or MIT license 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 for how it was written, CONTRIBUTING.md (clean-room rules apply) and 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.
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::appendcopies 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,
Arccontention 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 ofHashMap, the deliberate differences above) can still notice the change.