summaryrefslogtreecommitdiff
path: root/src/replica.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-18 10:19:31 -0300
committerGabriel Schneider <[email protected]>2026-11-18 10:19:31 -0300
commita2538c49b1bb69dcd1a6f1350834e13f68c3c05d (patch)
tree92c0cfb229d44974bf34ce6d4caa379142fbae44 /src/replica.zig
parentb2f709d7130571658220636f33b5f89414a5101a (diff)
parent5c5e0102f92938f433a3465c92818be810c1ef78 (diff)
downloadpardes-a2538c49b1bb69dcd1a6f1350834e13f68c3c05d.tar.gz
pardes-a2538c49b1bb69dcd1a6f1350834e13f68c3c05d.zip
integration: addons in a client part 3 (the core's prerequisites and the double free; the PDF kind where it is shown: a plain record and pages as draws) with the client path's round 1: no conflict; tui core-test 820/959 (139 skipped), shell-test 994/997, behaviour-test 274/274, replicas pass, pane-test 180/181; gui unit-test 1588/1592 (its perf check refuses the baseline by compiler version, as on the base), the tui build has no SDL symbol, the frame corpus 74/77 against mbase in Debug and ReleaseFast: frames 58 to 60 show WindowOpacity's notice alone where the base stacked it under InactiveDim's (a PDF render's answer no longer lands between the two ctl writes: accepted, and the baseline recorded anew as mbase2 with those three frames), the perf window -0.405% (threshold 0.5%)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/replica.zig')
-rw-r--r--src/replica.zig42
1 files changed, 33 insertions, 9 deletions
diff --git a/src/replica.zig b/src/replica.zig
index d10cdf83..f3ea3eee 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -852,13 +852,11 @@ pub const Replica = struct {
const u = parseUnit(msg) orelse return r.fail("a unit too short to read");
r.stats.units += 1;
if (u.origin == r.id) if (r.t.core) |c| r.echo.confirmed(c, u.seq);
- // A copy taken ahead (`ready`), nothing on top: the unit moves the
- // state it was of.
- if (r.applied == 0 and r.copy.held) {
- r.copy.release();
- rollback.Epoch.select(null);
- r.clearSince();
- }
+ // A copy taken ahead (`ready`), nothing on top: it stays the point a
+ // rollback goes back to, the unit replayed on it and kept in `since`,
+ // not let go and taken again (a megabyte walked) for each unit of
+ // the session's that comes while the client is idle.
+ const ahead = r.applied == 0 and r.copy.held;
if (r.guess) {
r.stamp = .{ .real_ns = u.real_ns, .mono_ns = u.mono_ns, .at_ns = nowNs() };
if (u.origin == r.id) for (r.pending.items) |p| if (p.seq == u.seq) {
@@ -931,7 +929,10 @@ pub const Replica = struct {
r.recovering = nowNs();
r.toConfirmed();
}
- r.moved = true;
+ // What it shows moved only when what a digest covers did: a unit of
+ // the session's pump that read its clock and moved nothing draws
+ // no frame.
+ if (ends == null or !std.mem.eql(u8, ends.?, r.last_digest.items)) r.moved = true;
if (tape.replayUnit(&r.t, u.tape)) |why| {
trace(r.gpa, "replica {d}: the unit of {d}/{d} diverged: {s}\n", .{ r.id, u.origin, u.seq, why }, &.{u.tape});
return r.fail(why);
@@ -942,6 +943,7 @@ pub const Replica = struct {
r.freePending(r.pending.orderedRemove(0));
}
r.dirty = true;
+ if (ahead) r.keepSince(u.tape);
}
fn fail(r: *Replica, why: []const u8) void {
@@ -955,6 +957,12 @@ pub const Replica = struct {
r.since.append(r.gpa, kept) catch return r.fail("out of memory");
if (r.since.items.len >= rebase_after) {
r.stats.rebases += 1;
+ // Nothing on top: it is the confirmed state already.
+ if (r.applied == 0) {
+ r.copy.release();
+ rollback.Epoch.select(null);
+ return r.clearSince();
+ }
r.toConfirmed();
r.dirty = true;
}
@@ -973,6 +981,8 @@ pub const Replica = struct {
const whole = r.copy.restore();
rollback.Epoch.select(null);
if (!whole) return r.fail("out of memory for a rollback");
+ // The frame its host drew is of the memory put back: drawn again.
+ r.moved = true;
// The rows a terminal was read as are no copy's: what the
// speculation built was the epoch's, freed with it, and what
// was there before is of a grid the deltas since moved on
@@ -1915,6 +1925,10 @@ pub const Peers = struct {
taken: std.ArrayListUnmanaged(Note) = .empty,
/// A reader posted: the loop's one test a step while nothing is attached.
mail: std.atomic.Value(bool) = .init(false),
+ /// ...and what it posted was a client's input or a join, which the
+ /// session steps at once; a terminal's acknowledgement waits for the
+ /// session's next frame, as its output does (tui.zig `waitInput`).
+ urgent: std.atomic.Value(bool) = .init(false),
/// Wakes the session's loop (its wait for input) from a reader.
wake_ctx: ?*anyopaque = null,
wake: ?*const fn (?*anyopaque) void = null,
@@ -1964,6 +1978,7 @@ pub const Peers = struct {
return;
};
ps.mail.store(true, .release);
+ if (note != .screen) ps.urgent.store(true, .release);
ps.lock.unlock(ps.io);
if (ps.wake) |w| w(ps.wake_ctx);
}
@@ -2938,6 +2953,10 @@ pub const Link = struct {
/// load took (PARDES_REPLICA_STATS).
join: struct { blobs: u32 = 0, from_memory: u32 = 0, from_disk: u32 = 0, sent_bytes: u64 = 0 } = .{},
join_ms: u64 = 0,
+ /// Frames it drew whole (`drawn`), and the last one presented again
+ /// moved on (its own motion), for PARDES_REPLICA_STATS.
+ draws: u32 = 0,
+ again: u32 = 0,
/// The test knobs the environment sets (PARDES_REPLICA_CHECK,
/// PARDES_TEST_DIVERGE).
@@ -3033,6 +3052,10 @@ pub const Link = struct {
if (drew) c.visible += 1;
}
c.dirty = false;
+ c.draws += 1;
+ // What moved before this frame is in it: not drawn again at the
+ // next unit (a stopped input's rollback, under its own frame).
+ c.r.moved = false;
while (c.r.screenRequest()) |req| if (!sendScreen(c.fd, req)) {
c.cut();
break;
@@ -3082,12 +3105,13 @@ pub const Link = struct {
var buf: [1024]u8 = undefined;
const e = &c.r.echo.stats;
var w: std.Io.Writer = .fixed(&buf);
- w.print("inputs {d} at_once {d} stopped {d} units {d} fast {d} neutral {d} mispredicted {d} foreign {d} visible {d} rtt_us {d} spec_us {d}/{d} copy_us {d}/{d} rollback_us {d}/{d} join_ms {d} blobs {d} from_memory {d} from_disk {d} sent_kb {d} echo {d}/{d} confirmed {d} missed {d}", .{
+ w.print("inputs {d} at_once {d} stopped {d} units {d} fast {d} neutral {d} mispredicted {d} foreign {d} visible {d} rtt_us {d} spec_us {d}/{d} copy_us {d}/{d} rollback_us {d}/{d} join_ms {d} blobs {d} from_memory {d} from_disk {d} sent_kb {d} echo {d}/{d} confirmed {d} missed {d} draws {d} again {d}", .{
st.inputs, st.speculated, st.stopped, st.units, st.fast,
c.r.neutral, st.mispredicted, st.foreign, c.visible, c.r.rtt_ns / 1000,
pctOf(st.spec_ns.items, 50) / 1000, pctOf(st.spec_ns.items, 99) / 1000, pctOf(st.copy_ns.items, 50) / 1000, pctOf(st.copy_ns.items, 99) / 1000, pctOf(st.rollback_ns.items, 50) / 1000,
pctOf(st.rollback_ns.items, 99) / 1000, c.join_ms, c.join.blobs, c.join.from_memory, c.join.from_disk,
c.join.sent_bytes >> 10, e.predicted, e.predicted + e.unpredicted, e.confirmed, e.mispredicted,
+ c.draws, c.again,
}) catch return;
// What stopped its inputs, last: a word a pair before it.
w.writeAll(" stops ") catch return;