From bce88593014a4078dc9259855944f9ddbc19fe54 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 23:14:10 -0300 Subject: views and the rollback copy: a live view's slot keeps no pointer into what the live core owns; a register's texts and a file's location rows are pinned, not copied views.zig: when a view goes live (to, close, drawOthers putting the live one back, only), its parked share is emptied (`emptied`): it was left holding copies of the pointers it handed the live fields (a column tag's text, a chord's argument, the presentation's), stale until it parked again. The rollback copy walks every slot: a stale pointer whose memory the live view had freed and another taken saved that other's bytes and put them back. A pane's share holds no pointer but its selections, which `unpark` already hands over. The test fails without it: a tag's text freed under view 0's stale slot, its memory taken by an allocation the copy has no business with, written under a held copy, and the copy put back. Registers.zig, locations.zig, rollback.zig: a register's values and joined text, and a file's location rows (the dropped ones, a query's saved), are replaced whole and never written, so the copy pins them as it does a file's text, freed raw (a safe build's free would write over one a copy still holds); rows pin whole with what each owns (`pinnedDeep`). In the harness at 30 ms the big copies were a file's location rows, 5-6 MB after the flood, not the register. ReleaseFast, 20 seeds, three clients, p99: copy 5.1 -> 0.22 ms at 30 ms (0.19-0.20 at 80 and 207); rollback 14.9 -> 9.5 ms at 30 ms (1.3-1.4 at 80 and 207), what is left being the replay's digests (half the harness's CPU is Wyhash over the whole core per replayed unit). Tests: a 2 MB register and 500 location rows pinned, not saved, and whole after a speculation drops them and the copy is put back. docs/next-daemon.md: the follow-ups. Co-Authored-By: Claude Opus 5.5 --- src/Registers.zig | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/Registers.zig') diff --git a/src/Registers.zig b/src/Registers.zig index 5e23da5b..760aff9a 100644 --- a/src/Registers.zig +++ b/src/Registers.zig @@ -5,12 +5,17 @@ //! computed from the editor rather than stored (`_`, `#`, `.`, `%`) and the //! clipboard's paste side are read in edit.zig, which has the pane at hand. const std = @import("std"); +const freeRaw = @import("memory.zig").freeRaw; const Registers = @This(); list: std.ArrayList(Reg) = .empty, last_search: u21 = '/', +/// A value and the joined text are replaced whole, never written in place, +/// so a replica's rollback copy pins them as it does a file's text +/// (src/rollback.zig `pinned`), and they are freed raw: a safe build's +/// free would write over one the copy still holds. pub const Reg = struct { name: u21, /// gpa-owned, one per range, in document order @@ -30,9 +35,9 @@ pub fn deinit(r: *Registers, gpa: std.mem.Allocator) void { } fn freeReg(gpa: std.mem.Allocator, reg: *Reg) void { - for (reg.values) |v| gpa.free(v); + for (reg.values) |v| freeRaw(gpa, v); gpa.free(reg.values); - if (reg.joined) |j| gpa.free(j); + if (reg.joined) |j| freeRaw(gpa, j); } pub fn get(r: *Registers, name: u21) ?*Reg { @@ -69,9 +74,9 @@ pub fn put(r: *Registers, gpa: std.mem.Allocator, name: u21, bytes: []const u8, freeReg(gpa, reg); reg.* = .{ .name = name, .values = values }; } - gpa.free(reg.values[i]); + freeRaw(gpa, reg.values[i]); reg.values[i] = copy; - if (reg.joined) |j| gpa.free(j); + if (reg.joined) |j| freeRaw(gpa, j); reg.joined = null; } -- cgit v1.3