From f264dbc4a646da695331fe7401fa013cbb720b6a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 00:25:19 -0300 Subject: the walker's digest: a blob's hash made once and folded in as a word (a 100 MB file was 5 ms a digest, two a unit, on the authority); blob fields annotated `.blob`, which the rollback copy's pins read too walk.zig: a field named in a type's `replica.blob` (a file's text, line index and location rows, an undo snapshot's text, a register's values and joined text, the rows an edit dropped, a query's saved rows) holds immutable blobs. A digest hashes one of 4 KiB or more once, keeps the word by its address and length, and folds the length and word in; `forget` drops the word, from memory.freeRaw and freeUnfilled, through which every such blob is freed raw. Only a Debug build (the tests, the harness, replay) hashes the bytes at every digest all the same and panics where the kept word is not their hash: a blob written in place, or freed past its word. A release build, ReleaseSafe the user's own as well as ReleaseFast, takes the word and never panics on a stale one: at worst a divergence, which a replica records and then stops at (nothing resets or rejoins it yet; the notes say so). File.zig: an edit's free of the old text went to `rawFree` itself and so kept its word; the next text of the same length at the same address folded in the old one (the ReleaseFast harness diverged in 162 of 180 replica runs, in `file.content`), and it goes through freeUnfilled now. Registers.zig: `put` makes a new values array rather than writing the old one. rollback.zig: the copy pins what `.blob` names (`pinned` and `pinnedDeep` gone). Measured, ReleaseFast on the perf cores: with a 100 MB file open (PARDES_DIGEST_BENCH=100, replica.zig's bench), a unit of a key into it went from p50 10.45 ms, p99 41.6 ms to p50 24 us, p99 6.1 ms (the first, which makes the word), a digest from 5.18 ms to 10 us. The harness (20 seeds x 120 inputs x 3 clients): rollback p99 9.5 -> 2.6 ms at 30 ms (1.5 and 1.4 ms at 80 and 207), copy p99 0.27 ms; none diverged, none unequal, no delta wrong. Tests: a blob hashed once, its kept word no longer its hash once written in place, its word gone when freed. docs/next-daemon.md: the follow-up. Co-Authored-By: Claude Opus 5.5 --- src/File.zig | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/File.zig') diff --git a/src/File.zig b/src/File.zig index 48a996a4..7acf8dd6 100644 --- a/src/File.zig +++ b/src/File.zig @@ -30,6 +30,7 @@ const long_paint: usize = 16 << 10; /// Content and primary selection at one file edit boundary. Keeping only the /// primary avoids putting Text.max_selections ranges in every history entry. pub const Snapshot = struct { + pub const replica = .{ .blob = .{"content"} }; content: []u8, cur_row: i32, cur_col: i32, @@ -139,7 +140,11 @@ pub const History = struct { pub const State = struct { /// What the replay digest leaves out (src/walk.zig): what is made again /// from the text whenever it is wanted. - pub const replica = .{ .derived = .{ "line_starts", "highlights", "highlight_start", "syntax_dirty", "node_tree", "node_tree_revision", "node_history", "tables" } }; + pub const replica = .{ + .derived = .{ "line_starts", "highlights", "highlight_start", "syntax_dirty", "node_tree", "node_tree_revision", "node_history", "tables" }, + // Replaced whole at every edit (setContentSpan), never written. + .blob = .{ "content", "line_starts", "location_rows" }, + }; path: []u8, content: []u8, @@ -840,6 +845,7 @@ fn reportEdit(p: *Pardes, f: *State, new: []const u8) void { } pub const DroppedMarks = struct { + pub const replica = .{ .blob = .{"rows"} }; len: usize, hash: u64, rows: []locations.Row, @@ -908,8 +914,8 @@ pub fn setContentSpan(p: *Pardes, f: *State, new: []u8, span_in: ?Span) void { f.saved_len = f.content.len; } // Raw: `free` overwrites a safe build's freed memory, a whole file's - // worth per keystroke. - if (f.content.len > 0) p.gpa.rawFree(f.content, .of(u8), @returnAddress()); + // worth per keystroke; and its digest word goes (src/walk.zig). + pardes.memory.freeUnfilled(p.gpa, f.content); f.content = new; f.revision +%= 1; f.splice = .{ .revision = f.revision, .head = known.head, .tail = known.tail, .old_len = old_len }; -- cgit v1.3