From ddb2554fff073eed0b73a43825b2c007c895bc4d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 05:58:13 -0300 Subject: replica: a far client's content cache and zstd: the session lists its join's blobs by BLAKE3 hash first (wire 16 `blobs`), the client finds each in the core it leaves or on disk ($XDG_CACHE_HOME/pardes/blobs, hashed again on load, a bad file a miss, the least recently used evicted past 1 GiB) and asks for the rest (`want`), and everything after the welcome goes in zstd envelopes (level 6 over 8 MiB for the join, an undo snapshot being a near copy of its text, then level 3), so `ssh -C` leaves the default command; a far client (through ssh, or PARDES_REPLICA_FAR) keeps what it was sent and, at its end, what it made; a hangup ends a remote client the normal way; through the box a client holding the blobs is drawn in 2.4 s where main took 7.0 to 11.9, and a first join of a session with undo in 7.1 s where main took 11.9; libzstd 1.5.7 vendored, its allocations on c_heap, a second copy refused by shared-libs-check; tests for the cache's verify-on-load, its eviction and a far join's blobs sent once; test/daemon.py's far clients Co-Authored-By: Claude Opus 5.5 --- src/walk.zig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/walk.zig') diff --git a/src/walk.zig b/src/walk.zig index 3556ce88..1c5bbbfc 100644 --- a/src/walk.zig +++ b/src/walk.zig @@ -111,6 +111,10 @@ fn hashBlob(comptime E: type, items: []const E, h: *Hasher) void { const b = blob_words.get(addr) orelse break :kept null; break :kept if (b.len == items.len) b.word else null; } else null; + if (blobs_out) |list| { + list.append(std.heap.c_allocator, std.mem.sliceAsBytes(items)) catch {}; + break :word 0; + } if (!rehash) if (kept) |w| break :word w; if (E == u8) if (unhashed_out) |list| if (kept == null) { list.append(std.heap.c_allocator, items) catch {}; @@ -136,6 +140,17 @@ fn hashBlob(comptime E: type, items: []const E, h: *Hasher) void { /// Where `unhashed` notes the texts a digest would hash for want of a word. threadlocal var unhashed_out: ?*std.ArrayListUnmanaged([]const u8) = null; +/// Where `blobs` notes every blob, hashing none. +threadlocal var blobs_out: ?*std.ArrayListUnmanaged([]const u8) = null; + +/// Every blob of `v` a digest would take as one (`blob_min` bytes and up), +/// as its bytes, onto `out` (the C heap's), hashed by none: a replica +/// client's, which knows its blobs by content (src/replica.zig `Have`). +pub fn blobs(comptime T: type, v: *const T, out: *std.ArrayListUnmanaged([]const u8)) void { + blobs_out = out; + defer blobs_out = null; + _ = digest(T, v); +} /// The blob texts a digest of `v` would hash now, having no word yet, onto /// `out` (the C heap's): a walk with no blob hashed, which `makeWords` then -- cgit v1.3