Fix performance regression in multibuffer diff syncing (#26137)
This fixes a performance problem introduced in #25906 and caused by calling `BufferDiff::snapshot` too frequently. Release Notes: - Fixed a performance regression related to buffer diffs Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
parent
aaa506c061
commit
ad9c508a72
1 changed files with 9 additions and 3 deletions
|
@ -2045,6 +2045,7 @@ impl MultiBuffer {
|
||||||
.cursor::<(Option<&Locator>, ExcerptOffset)>(&());
|
.cursor::<(Option<&Locator>, ExcerptOffset)>(&());
|
||||||
let mut edits = Vec::new();
|
let mut edits = Vec::new();
|
||||||
let mut excerpt_ids = ids.iter().copied().peekable();
|
let mut excerpt_ids = ids.iter().copied().peekable();
|
||||||
|
let mut removed_buffer_ids = Vec::new();
|
||||||
|
|
||||||
while let Some(excerpt_id) = excerpt_ids.next() {
|
while let Some(excerpt_id) = excerpt_ids.next() {
|
||||||
// Seek to the next excerpt to remove, preserving any preceding excerpts.
|
// Seek to the next excerpt to remove, preserving any preceding excerpts.
|
||||||
|
@ -2067,7 +2068,7 @@ impl MultiBuffer {
|
||||||
excerpt.buffer_id
|
excerpt.buffer_id
|
||||||
);
|
);
|
||||||
buffers.remove(&excerpt.buffer_id);
|
buffers.remove(&excerpt.buffer_id);
|
||||||
self.diffs.remove(&excerpt.buffer_id);
|
removed_buffer_ids.push(excerpt.buffer_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursor.next(&());
|
cursor.next(&());
|
||||||
|
@ -2108,6 +2109,10 @@ impl MultiBuffer {
|
||||||
new_excerpts.append(suffix, &());
|
new_excerpts.append(suffix, &());
|
||||||
drop(cursor);
|
drop(cursor);
|
||||||
snapshot.excerpts = new_excerpts;
|
snapshot.excerpts = new_excerpts;
|
||||||
|
for buffer_id in removed_buffer_ids {
|
||||||
|
self.diffs.remove(&buffer_id);
|
||||||
|
snapshot.diffs.remove(&buffer_id);
|
||||||
|
}
|
||||||
|
|
||||||
if changed_trailing_excerpt {
|
if changed_trailing_excerpt {
|
||||||
snapshot.trailing_excerpt_update_count += 1;
|
snapshot.trailing_excerpt_update_count += 1;
|
||||||
|
@ -2741,9 +2746,10 @@ impl MultiBuffer {
|
||||||
snapshot.has_deleted_file = has_deleted_file;
|
snapshot.has_deleted_file = has_deleted_file;
|
||||||
snapshot.has_conflict = has_conflict;
|
snapshot.has_conflict = has_conflict;
|
||||||
|
|
||||||
snapshot.diffs.retain(|_, _| false);
|
|
||||||
for (id, diff) in self.diffs.iter() {
|
for (id, diff) in self.diffs.iter() {
|
||||||
snapshot.diffs.insert(*id, diff.diff.read(cx).snapshot(cx));
|
if snapshot.diffs.get(&id).is_none() {
|
||||||
|
snapshot.diffs.insert(*id, diff.diff.read(cx).snapshot(cx));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
excerpts_to_edit.sort_unstable_by_key(|(locator, _, _)| *locator);
|
excerpts_to_edit.sort_unstable_by_key(|(locator, _, _)| *locator);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue