From 0d07182abfa2cb02c5351231af2f1e1a156a59af Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 5 Nov 2026 19:53:07 -0300 Subject: digest: a blob of 4 KiB and up (a file's text, a register's text, a file's rows, an undo entry's bytes) is taken as its length, never its bytes, a text's revision saying what it holds, where it was hashed once and kept as a word by its address (walk.zig's blob words, from when no text was written in place): since the journal a session's edit writes its text in place, and since the change before a replica's does too, so the word went at every edit and the next unit's digest hashed the whole text again, 100 MB of it in a big file, on the session's step and the replica's; the words go with what kept them (walk.forget, wordOf, forgetAll, unhashed, makeWords, the bench's blob_words_on, memory.freeRaw's and unpin's forgets, File.edit's and grow's), and so does the join's hashing thread (replica.Peers' held, texts, hasher and rounds, joins, hashTexts, unhashedDone, the `hashed` note), which made the words of the texts a session never digested before a join's digest took them, its pins with it: a client is joined at the boundary its connection comes at; the semantics change, so the wire's version is 20 (a client of the build before is refused at its hello, as any other build's, and test/daemon.py's own hello says 20); a blob under 4 KiB is hashed whole as before, so a small text's bytes stay in the digest, and the replicas harness (test/replicas.zig) compares every file's text byte for byte at quiescence beside the digest; tests: walk.zig's 'a blob is hashed once and folded in as a word; one written in place is not its word, which a Debug build checks; a freed one's word goes' becomes 'a blob of 4 KiB and up is digested by its length, what it holds told by its keeper's revision; a smaller one by its bytes' Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/replica.zig | 75 ++++++--------------------------------------------------- 1 file changed, 7 insertions(+), 68 deletions(-) (limited to 'src/replica.zig') diff --git a/src/replica.zig b/src/replica.zig index f58a4b27..71528fc4 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -947,9 +947,6 @@ pub const Replica = struct { c.update(in.event); c.step(); p.terminal = r.t.screen_state and (keyboard or r.t.touched); - // No digest is taken here: a blob born under the copy and digested - // keeps its word past the epoch's free of it (src/walk.zig), and a - // later blob at that address read as it. const clean = tape.endSpeculation(&r.t); const dt = nowNs() - t0; // Where a blob was written, should one be: the input that did. @@ -1455,7 +1452,7 @@ pub const Peer = struct { /// state, then the blobs it says it lacks; what follows the join goes /// in a cheaper frame. The hashing is this thread's, never the step's. /// ponytail: a blob is hashed again at every far join, 3.6 GB/s; a - /// session's join after its first would keep them, beside its words. + /// session's join after its first could keep them. fn farJoin(peer: *Peer) bool { const gpa = peer.peers.gpa; peer.z = zstd.compressor(6, 23) orelse return false; @@ -1736,14 +1733,8 @@ pub const Peers = struct { /// it records: what each was sent. screens: Screens = undefined, msgs: std.ArrayListUnmanaged([]u8) = .empty, - /// Clients waiting to join while the session's texts are hashed - /// (`joins`), the texts and the thread hashing them. - held: std.ArrayListUnmanaged(Joining) = .empty, - texts: std.ArrayListUnmanaged([]const u8) = .empty, - hasher: ?std.Thread = null, - rounds: u8 = 0, - - pub const Note = union(enum) { join: Joining, input: Msg, screen: Msg, gone: *Peer, check: *Peer, joined: *Peer, hashed }; + + pub const Note = union(enum) { join: Joining, input: Msg, screen: Msg, gone: *Peer, check: *Peer, joined: *Peer }; /// A connection to join, and the view it joins again for, if it does. pub const Joining = daemon.Joining; pub const Msg = struct { peer: *Peer, msg: []u8 }; @@ -1761,7 +1752,7 @@ pub const Peers = struct { switch (note) { .join => |j| _ = libc.close(j.fd), .input, .screen => |in| ps.gpa.free(in.msg), - .gone, .check, .joined, .hashed => {}, + .gone, .check, .joined => {}, } return; }; @@ -1812,17 +1803,7 @@ pub const Peers = struct { ps.mail.store(false, .release); ps.lock.unlock(ps.io); for (ps.taken.items) |note| switch (note) { - .join => |j| { - ps.held.append(ps.gpa, j) catch { - daemon.refuseReplica(j.fd, "out of memory"); - continue; - }; - ps.joins(core); - }, - .hashed => { - ps.unhashedDone(); - ps.joins(core); - }, + .join => |j| ps.join(core, j), .input => |in| { ps.input(core, in.peer, in.msg); ps.gpa.free(in.msg); @@ -1885,42 +1866,6 @@ pub const Peers = struct { } } - /// The clients waiting to join, joined, once the texts the session - /// never digested have their words (`walk.unhashed`): those are hashed - /// on a thread of their own, pinned meanwhile, and the joins wait a - /// boundary or two for them, the session's step never. A second round - /// joins whatever is left. - fn joins(ps: *Peers, core: *Pardes) void { - if (ps.hasher != null or ps.held.items.len == 0) return; - if (ps.rounds < 2) { - walk.unhashed(Pardes, core, &ps.texts); - if (ps.texts.items.len > 0) { - for (ps.texts.items) |b| pardes.memory.pin(b); - if (std.Thread.spawn(.{}, hashTexts, .{ps})) |t| { - ps.hasher = t; - ps.rounds += 1; - return; - } else |_| ps.unhashedDone(); - } - } - ps.rounds = 0; - for (ps.held.items) |j| ps.join(core, j); - ps.held.clearRetainingCapacity(); - } - - fn hashTexts(ps: *Peers) void { - walk.makeWords(ps.texts.items); - ps.post(.hashed); - } - - /// The hashing thread joined, its texts unpinned. - fn unhashedDone(ps: *Peers) void { - if (ps.hasher) |t| t.join(); - ps.hasher = null; - for (ps.texts.items) |b| pardes.memory.unpin(b); - ps.texts.clearRetainingCapacity(); - } - fn join(ps: *Peers, core: *Pardes, joining: Joining) void { const fd = joining.fd; const t0 = nowNs(); @@ -2064,7 +2009,7 @@ pub const Peers = struct { const mine = switch (ps.inbox.items[i]) { .input, .screen => |in| in.peer == peer, .gone, .check, .joined => |p| p == peer, - .join, .hashed => false, + .join => false, }; if (!mine) { i += 1; @@ -2145,10 +2090,6 @@ pub const Peers = struct { /// ...each view kept for its client if `again` (an Upgrade's). fn drop(ps: *Peers, core: *Pardes, again: bool) void { - ps.unhashedDone(); - for (ps.held.items) |j| _ = libc.close(j.fd); - ps.held.clearRetainingCapacity(); - ps.rounds = 0; for (&ps.list) |*slot| if (slot.*) |peer| { slot.* = null; core.undrawn &= ~(@as(u8, 1) << @intCast(peer.view)); @@ -2161,7 +2102,7 @@ pub const Peers = struct { for (ps.inbox.items) |note| switch (note) { .join => |j| _ = libc.close(j.fd), .input, .screen => |in| ps.gpa.free(in.msg), - .gone, .check, .joined, .hashed => {}, + .gone, .check, .joined => {}, }; ps.inbox.clearRetainingCapacity(); ps.lock.unlock(ps.io); @@ -2175,8 +2116,6 @@ pub const Peers = struct { ps.input_ns.deinit(ps.gpa); ps.boundary_ns.deinit(ps.gpa); ps.msgs.deinit(ps.gpa); - ps.held.deinit(ps.gpa); - ps.texts.deinit(std.heap.c_allocator); ps.each_join.deinit(ps.gpa); } -- cgit v1.3