From 3ebf0641cb3b07440460ceb26f20c272fabe8eaf Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 2 Nov 2026 23:45:53 -0500 Subject: [PATCH] fix(collab): place keyed-list puts through an index within a batch (#1893) * fix(collab): place keyed-list puts through an index within a batch Each Put of a comment, style, variable or collection scanned the whole list for its key (cloning String keys on the way) before appending, so a batch of N new entries cost N squared comparisons on the hub every session shares. Removing an image also rebuilt the document's image-use set before checking the image existed. Replica::apply now keeps a per-batch key index for each keyed list; it is rebuilt when the list's length or the entry at a key no longer matches, and dropped on whole-list sets, reorders and real removals. Removing an absent entry or image returns without scanning. * fix(collab): keep the keyed-list index current through removals Build the index without dead code outside tests, drop the wall-clock assertion from the large-batch test, and shift the index down after a single-entry removal instead of discarding it, so a run of removals in one batch does not index the list again each time. Staleness checks for puts and removals share one helper. Tests cover removals, duplicate keys from a whole-list set, and absent keys. --- crates/collab/src/docprops.rs | 152 +++++++++++++++++++++----- crates/collab/src/keyed_list_tests.rs | 132 ++++++++++++++++++++++ crates/collab/src/lib.rs | 2 + crates/collab/src/replica.rs | 7 +- 4 files changed, 261 insertions(+), 32 deletions(-) create mode 100644 crates/collab/src/keyed_list_tests.rs diff --git a/crates/collab/src/docprops.rs b/crates/collab/src/docprops.rs index e203d2c3b..b590064df 100644 --- a/crates/collab/src/docprops.rs +++ b/crates/collab/src/docprops.rs @@ -54,18 +54,71 @@ struct List { entry: fn(T::Key) -> Entry, get: fn(&Document) -> &Vec, get_mut: fn(&mut Document) -> &mut Vec, + /// The list's slot in an [`Index`]. + index: fn(&mut Index) -> &mut Option>, } -const STYLES: List