diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-30 00:25:19 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-30 00:53:24 -0300 |
| commit | f264dbc4a646da695331fe7401fa013cbb720b6a (patch) | |
| tree | b8d960c5034d7ebfeb44fa25fa5697abbf386a9f /src/rollback.zig | |
| parent | bce88593014a4078dc9259855944f9ddbc19fe54 (diff) | |
| download | pardes-f264dbc4a646da695331fe7401fa013cbb720b6a.tar.gz pardes-f264dbc4a646da695331fe7401fa013cbb720b6a.zip | |
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 <[email protected]>
Diffstat (limited to 'src/rollback.zig')
| -rw-r--r-- | src/rollback.zig | 36 |
1 files changed, 5 insertions, 31 deletions
diff --git a/src/rollback.zig b/src/rollback.zig index a7027da6..37fc481d 100644 --- a/src/rollback.zig +++ b/src/rollback.zig @@ -35,8 +35,8 @@ const Allocator = std.mem.Allocator; const Alignment = std.mem.Alignment; const Pardes = pardes.Pardes; -/// Blobs this long or longer (`pinned`) are pinned, not copied. Checked -/// unchanged in a safe build when the copy goes. +/// Blobs (walk.blob: fields annotated `.blob`) this long or longer are +/// pinned, not copied. Checked unchanged in a safe build when the copy goes. const blob_min = 4096; const checked = builtin.mode == .debug or builtin.mode == .safe; @@ -198,8 +198,6 @@ pub const Copy = struct { /// of the blobs: a file's text or an undo snapshot's. where: []const u8 = "", pinnable: bool = false, - /// Whether it is a blob of rows that own allocations of their own. - deep: bool = false, const Region = struct { addr: usize, off: usize, len: usize }; const Pin = struct { addr: usize, len: usize, hash: u64, where: []const u8 }; @@ -344,8 +342,7 @@ pub const Copy = struct { if (attr.@"comptime" or comptime (annotated(T, "authority", name) or ((annotated(T, "local", name) or annotated(T, "derived", name)) and unsaved(name)))) continue; if (comptime opaqueTo(F)) continue; c.where = @typeName(T) ++ "." ++ name; - c.pinnable = comptime pinned(T, name); - c.deep = comptime pinnedDeep(T, name); + c.pinnable = comptime walk.blob(T, name); if (comptime walk.lengthOf(T, name) != null and @typeInfo(F) == .array) { const len = comptime walk.lengthOf(T, name).?; if (comptime heapIn(@typeInfo(F).array.child, 0)) for (@field(v, name)[0..walk.lengthIn(v, len)]) |*e| try c.visit(@typeInfo(F).array.child, e); @@ -398,9 +395,8 @@ pub const Copy = struct { if (s.len == 0) return; const addr = @intFromPtr(s.ptr); if (try c.reached([]const E, addr)) return; - const flat = comptime !heapIn(E, 0); - if ((if (flat) c.pinnable else c.deep) and s.len * @sizeOf(E) >= blob_min and c.epoch.?.owns(addr) != null) { - // A blob of rows with allocations of their own pinned whole: + if (c.pinnable and s.len * @sizeOf(E) >= blob_min and c.epoch.?.owns(addr) != null) { + // A blob of rows with allocations of their own is pinned whole: // they are as immutable as it, and kept alive with it. const bytes = std.mem.sliceAsBytes(s); try c.pins.append(c.meta, .{ .addr = addr, .len = bytes.len, .hash = if (checked) std.hash.Wyhash.hash(0, bytes) else 0, .where = c.where }); @@ -411,28 +407,6 @@ pub const Copy = struct { } }; -/// The blobs: what an edit puts in place of its predecessor, never writes -/// (File.setContentSpan), and frees raw (memory.freeUnfilled, freeRaw). -fn pinned(comptime T: type, comptime name: []const u8) bool { - const File = pardes.panes.File; - return (T == File.State and (std.mem.eql(u8, name, "content") or std.mem.eql(u8, name, "line_starts"))) or - (T == File.Snapshot and std.mem.eql(u8, name, "content")) or - // A register's values and joined text: a yank of a terminal's whole - // grid is megabytes, which every speculation would otherwise copy. - (T == pardes.Registers.Reg and (std.mem.eql(u8, name, "values") or std.mem.eql(u8, name, "joined"))); -} - -/// Blobs of rows that own allocations of their own (a location's path, its -/// colours), the array and they replaced whole and never written, freed raw -/// (locations.freeRows): a file's location rows (5 MB after a flood of -/// search results), the ones an edit dropped, a query's saved. -fn pinnedDeep(comptime T: type, comptime name: []const u8) bool { - const File = pardes.panes.File; - return (T == File.State and std.mem.eql(u8, name, "location_rows")) or - (T == File.DroppedMarks and std.mem.eql(u8, name, "rows")) or - (T == pardes.panes.Query.Saved and std.mem.eql(u8, name, "rows")); -} - fn annotatedStruct(comptime T: type) bool { return @typeInfo(T) == .@"struct" and @hasDecl(T, "replica"); } |
