summaryrefslogtreecommitdiff
path: root/src/hunks.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-23 17:10:58 -0300
committerGabriel Schneider <[email protected]>2026-10-23 17:10:58 -0300
commit0073d05329335dbb0eb85f5c3044e42805d144e5 (patch)
tree744edfc317719b2018b1c3a8657c223aec058d47 /src/hunks.zig
parenta8b457a306a4442975210bcac3f04b56513c61c3 (diff)
downloadpardes-0073d05329335dbb0eb85f5c3044e42805d144e5.tar.gz
pardes-0073d05329335dbb0eb85f5c3044e42805d144e5.zip
Callstack lists every caller and pages a tree too big for one query; memory bounds and resident-size fixes
Callstack walks while the server answers, counts on the message row past a second, puts test callers last at each level, and ends a tree past one query's memory (memory.limits.arena.lsp_query, a 256 MiB region taken and given back per query) in a row whose Callstack shows the next page. Grep reads whole files. New hard limits: undo text per file, image decode pixels, the LSP snapshot of other open files, one paste. Safe builds no longer fill worst-case buffers with 0xAA (memory.unfilled), big regions are kept off transparent huge pages, and malloc_trim runs after big results. Also: Look's git show pages into a +Diff, and dropped marks in File. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/hunks.zig')
-rw-r--r--src/hunks.zig19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/hunks.zig b/src/hunks.zig
index 73c0654a..24aaf63d 100644
--- a/src/hunks.zig
+++ b/src/hunks.zig
@@ -368,21 +368,34 @@ const max_line_distance = 0.6;
/// rather than aligned at a quadratic cost (delta aligns them all).
const max_run = 256;
const max_cells = 1 << 16;
+/// Pairs one hunk compares (each a table of up to `max_cells`): past it, the
+/// rest of its lines are shown unemphasised. And the scratch each pair is
+/// aligned in, reused by the next: its table and the ranges it marks.
+const max_pairs = 4096;
+const pair_scratch_bytes = 8 << 20;
/// Pair each removed line with the first added line after the last one
/// paired that is near enough to it, in order, and emphasise in both the
/// tokens one has and the other has not.
fn inferEdits(arena: std.mem.Allocator, minus: []HunkLine, plus: []HunkLine) !void {
if (minus.len == 0 or plus.len == 0 or minus.len > max_run or plus.len > max_run) return;
+ const plus_tokens = try arena.alloc([]const []const u8, plus.len);
+ for (plus, plus_tokens) |line, *tokens| tokens.* = try tokenize(arena, line.code);
+ var scratch: std.heap.FixedBufferAllocator = .init(try @import("memory.zig").unfilled(arena, pair_scratch_bytes));
+ var pairs: usize = 0;
var plus_index: usize = 0;
for (minus) |*m| {
const m_tokens = try tokenize(arena, m.code);
var j = plus_index;
while (j < plus.len) : (j += 1) {
- const p_tokens = try tokenize(arena, plus[j].code);
+ const p_tokens = plus_tokens[j];
if ((m_tokens.len + 1) * (p_tokens.len + 1) > max_cells) continue;
- var alignment = try Alignment.init(arena, m_tokens, p_tokens);
- const marks = try annotate(arena, &alignment, m.code, plus[j].code);
+ if (pairs == max_pairs) return;
+ pairs += 1;
+ scratch.reset();
+ const pair = scratch.allocator();
+ var alignment = Alignment.init(pair, m_tokens, p_tokens) catch continue;
+ const marks = annotate(pair, &alignment, m.code, plus[j].code) catch continue;
if (marks.distance > max_line_distance) continue;
for (marks.minus) |r| for (m.styles[r[0]..r[1]]) |*b| {
b.* |= syntax.diff_emph;