Use diff summary for action log stats instead of iterating hunks (#61272)

The diff already has a constant-time accessor to get the counts of
added/removed rows, use that instead of iterating hunks on the
foreground.

Release Notes:
- Improved performance in agent threads with many file changes.
This commit is contained in:
Cole Miller authored and GitHub committed 2026-07-20 16:17:02 +00:00
1 parent 8e1f9eabc0
commit 87a08f30eb
3 files changed
+14 -19

No files matched your search

+7 -18
View File
@@ -1047,23 +1047,12 @@ pub struct DiffStats {
}
impl DiffStats {
pub fn single_file(buffer: &Buffer, diff: &BufferDiff, cx: &App) -> Self {
let mut stats = DiffStats::default();
let diff_snapshot = diff.snapshot(cx);
let buffer_snapshot = buffer.snapshot();
let base_text = diff_snapshot.base_text();
for hunk in diff_snapshot.hunks(&buffer_snapshot) {
let added_rows = hunk.range.end.row.saturating_sub(hunk.range.start.row);
stats.lines_added += added_rows;
let base_start = hunk.diff_base_byte_range.start.to_point(base_text).row;
let base_end = hunk.diff_base_byte_range.end.to_point(base_text).row;
let removed_rows = base_end.saturating_sub(base_start);
stats.lines_removed += removed_rows;
pub fn single_file(diff: &BufferDiff) -> Self {
let (lines_added, lines_removed) = diff.changed_row_counts();
DiffStats {
lines_added,
lines_removed,
}
stats
}
pub fn all_files(
@@ -1071,8 +1060,8 @@ impl DiffStats {
cx: &App,
) -> Self {
let mut total = DiffStats::default();
for (buffer, diff) in changed_buffers {
let stats = DiffStats::single_file(buffer.read(cx), diff.read(cx), cx);
for (_, diff) in changed_buffers {
let stats = DiffStats::single_file(diff.read(cx));
total.lines_added += stats.lines_added;
total.lines_removed += stats.lines_removed;
}
@@ -3215,7 +3215,7 @@ impl ThreadView {
.size(IconSize::Small)
});
let file_stats = DiffStats::single_file(buffer.read(cx), diff.read(cx), cx);
let file_stats = DiffStats::single_file(diff.read(cx));
let buttons = self.render_edited_files_buttons(
index,
+6
View File
@@ -2122,6 +2122,12 @@ impl BufferDiff {
.is_some_and(|diff_snapshot| diff_snapshot.base_text_exists)
}
pub fn changed_row_counts(&self) -> (u32, u32) {
self.diff_snapshot
.as_ref()
.map_or((0, 0), |diff_snapshot| diff_snapshot.changed_row_counts())
}
pub fn snapshot(&self, cx: &App) -> BufferDiffSnapshot {
let mut snapshot = self.diff_snapshot.clone().unwrap_or_else(|| {
let base_text = self.base_text_buffer.read(cx).snapshot();