Commit Graph
2 Commits
Author SHA1 Message Date
dotCooCoo 464dcb71d7 craft-shared-vec: make small range edits as single edits
append, split_off, truncate, splice and retain rebuilt every branch
from the leaves, so removing one element of 100,000 through splice or
retain counted about 40 KB, against 2.8 KB for remove. They now make
their changes as single edits when they remove or insert only a few
elements, and rebuild only when the single edits could copy as many
blocks. Removing one element through splice or retain now counts the
same as remove.

- An empty list does not allocate: the root is None until the first
  element, so two empty lists hold no blocks and count 0 bytes.
- An insertion into a shared leaf copies it once, into a block with
  room for the new element, instead of copying and then reallocating.
- The leaf walk keeps 12 levels, and its comment states the size of
  the deepest tree it handles.
- The benchmark times only the edit on both sides, and says the bytes
  per edit are computed. The Vec times were inflated by the snapshot
  drop: 296 us per edit at 100,000 elements, not 579 us.
- The docs say what a block's bytes cover, and what a panicking
  T::clone leaves behind.
2026-11-22 10:08:20 -08:00
dotCooCoo fb66ff092e Add craft-shared-vec: an indexed list whose clones share their blocks
A document tree that keeps each container's children in an Arc<Vec<_>>
and edits them with Arc::make_mut copies the whole child list on every
edit while an undo snapshot still holds it. One edit on a layer of
100,000 objects copies 800 KB of handles.

SharedVec<T> keeps elements in leaves of up to 64 under a counted
B-tree with Arc blocks. get, set, get_mut, insert, remove, push and pop
take O(log n) and copy only the blocks on their path; append,
split_off, truncate, splice and retain rebuild the branches and keep
every leaf they do not change. bytes_not_in and bytes_not_in_with count
the blocks and element payloads one list holds and another does not,
for undo-history limits. With the serde feature a list reads and writes
as a plain sequence, the same bytes as a Vec.

The examples/bench.rs example times edits beside a kept snapshot and
iteration against Vec.
2026-11-22 09:49:02 -08:00