summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 15:38:35 -0300
committerGabriel Schneider <[email protected]>2026-10-30 16:49:16 -0300
commit470b8098a53ad3b3b0a2ef90f0d43416ea50a9b0 (patch)
treeb9cfc3118cfed851d3dadd3f42280cf305497f55
parent020a7d24103a7c6f788db1091fd921d41d0df9e8 (diff)
downloadpardes-470b8098a53ad3b3b0a2ef90f0d43416ea50a9b0.tar.gz
pardes-470b8098a53ad3b3b0a2ef90f0d43416ea50a9b0.zip
Places: the lowered copy a smart-case search reads is zeroed where it is made: its pieces not lowered yet were whatever the heap held, in every digest and a join's dump, so two processes' places differed (H5's and H17's `places.hits|hay`)
freshHay took `memory.unfilled` and lowered a piece at a time as the search reached it; the digest and the dump take the whole slice. Zeroing it costs 20 us for 1 MB, 0.4 ms for 10 MB and 10 ms for 100 MB in one frame (ReleaseFast, page faults included; lowering the same text is four times that, spread over frames), the order of the copy an edit of that text already makes. Test (failing before): two sessions searching one text, each heap handing out other bytes (rollback.Epoch.fill), digest the same places. Co-Authored-By: Claude Opus 5.5 <[email protected]>
-rw-r--r--src/Places.zig32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Places.zig b/src/Places.zig
index 3dca3adf..818ca1d7 100644
--- a/src/Places.zig
+++ b/src/Places.zig
@@ -264,6 +264,14 @@ fn freshHay(set: *Places, gpa: std.mem.Allocator, f: *File.State) bool {
if (set.hay.len > 0) gpa.rawFree(set.hay, .of(u8), @returnAddress());
set.hay = &.{};
set.hay = memory.unfilled(gpa, f.content.len) catch return false;
+ // What is not lowered yet is in the digest and a dump as well: zeros,
+ // the same in every process, not whatever its heap held (a replica's
+ // diverged). A pass over the text, as the edit that made it was.
+ // ponytail: 0.4 ms for 10 MB, 10 ms for 100 MB in one frame (ReleaseFast,
+ // page faults and all; lowering it is four times that, over frames). A
+ // digest and a dump of the lowered pieces alone if a huge text's first
+ // search ever shows.
+ @memset(set.hay, 0);
set.low.resize(gpa, (f.content.len + chunk_bytes - 1) / chunk_bytes, false) catch return false;
set.low.unsetAll();
set.hay_revision = f.revision;
@@ -880,3 +888,27 @@ test "zz stress analysis cost" {
std.testing.allocator.free(a.colors);
std.debug.print("decls {d} us ({d}), analysis with colours {d} us\n", .{ (t1 - t0) / 1000, d.len, (t2 - t1) / 1000 });
}
+
+test "a lowered copy's pieces not searched yet are the same in every process: a digest and a dump take them" {
+ // Two sessions searching one text, each heap handing out other bytes in
+ // what is not written yet (rollback.Epoch.fill): their places agree.
+ const rollback = @import("rollback.zig");
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(std.testing.allocator);
+ for (0..2000) |i| try text.print(std.testing.allocator, "line {d} of a text in four pieces\n", .{i});
+ var digests: [2]u64 = undefined;
+ for (&digests, [_]u8{ 0x11, 0x5a }) |*d, b| {
+ var e: rollback.Epoch = .{ .child = std.testing.allocator };
+ defer e.deinit();
+ rollback.Epoch.fill = b;
+ defer rollback.Epoch.fill = null;
+ const p = try Pardes.init(e.allocator(), .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer p.deinit();
+ const pane = try p.setTestFile(text.items);
+ // The view's piece found now, the rest a frame at a time after.
+ pane.places.search(p, pane, .typed, 0, "piece", false, null, false);
+ try std.testing.expect(!pane.places.complete() and pane.places.fold);
+ d.* = pardes.walk.digest(Places, &pane.places);
+ }
+ try std.testing.expectEqual(digests[0], digests[1]);
+}