diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 10:20:02 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 11:40:11 -0300 |
| commit | eae5736ad923731135dd35b3783c90a3358bd0fa (patch) | |
| tree | bcb617da9c6501eae32c26332eff8c8f1b53c47e /core | |
| parent | 40c9f9ac0b6bf46ed8f1be162cf3c2b58d3e2513 (diff) | |
| download | pardes-eae5736ad923731135dd35b3783c90a3358bd0fa.tar.gz pardes-eae5736ad923731135dd35b3783c90a3358bd0fa.zip | |
replica: a client's input is sent before it is applied (the reorganisation's runners, step 10b, its fourth part; the design round's step 1): Replica.input is now its two halves, pend (working name: the input stamped, numbered and pending, its message for the session in r.out) and applyPended (working name: settled, applied at once when it can be, its echo predicted), and Link.input sends between them, so the session starts its step while the client speculates (a key into a shell stops at pty_write and is undone, which the session no longer waits behind); Replica.input stays both halves for the tests and the walk; the client-path kit's key into a shell pane (a pardes --detach session and pardes --attach in a terminal, ReleaseFast, 6 blocks of 30 keys, before and after interleaved twice, the machine loaded 5 to 12): with the predicted echo off, the shell's own echo (the whole round: the client's input sent, the session's step, the pty, the delta, the client's frame) first shown at min 16.05/16.00 -> 15.83/15.83 ms, median 16.30/16.27 -> 16.15/16.15 ms, the client's instructions a key 8.46M/8.77M -> 8.46M/8.52M, the session's 1.138M -> 1.138M; with the echo on (the predicted echo drawn at once) median 0.74/0.71 -> 0.95/0.70 ms, within its noise. Gate: tui core-test 837/980 (143 skipped), shell-test 1015/1018, term-test 15/15, pane-test 183/184, kitty-test 45/45, behaviour-test 275/275 and --replay 275/275, process-test lspcomplete and lspcompletemoved (the base's) and `Lspinfo opens one +Lsp pane` (a Hangup in the loaded run; alone three times of three PASS); gui unit-test 1613/1617 with the base's BaselineHarnessMismatch; the soak (--clients 5) as change 3's, diverged 0, unequal 0, deltas wrong 0, quiet checks 526/0, 550/0, 811/0, unlisted 0 (its delayed link reads the socket after the loop's pass, so the order of send and apply is not visible to it); daemon.py plain, --far, --games, --window-clients, --upgrade from pardes-tree's pfx-base to this and back; the macOS library for Linux and aarch64-macos and the FreeBSD tui configure; rollback-bench runs; gate-w run3-4 against tree1: frames 77/77 byte-identical in Debug, unit-test 1613/1617 (no failure the base has not), the alternated windows' pictures identical in all 10 runs, corpus2x +0.061%, perfops 97 counts within 0.1% (largest image-frame on longline +0.032%)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core')
| -rw-r--r-- | core/replica.zig | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/core/replica.zig b/core/replica.zig index c9a69bdf..01a0b79d 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -835,6 +835,16 @@ pub const Replica = struct { /// The replica's own input: applied at once when it can be, and the /// message for the authority returned (valid until the next call). pub fn input(r: *Replica, ev: pardes.Event) ![]const u8 { + const msg = try r.pend(ev); + r.applyPended(ev); + return msg; + } + + /// An input's first half: stamped, numbered and pending, its message + /// for the authority returned (valid until the next call), which a + /// client sends before it applies it (`applyPended`, Link.input): the + /// session starts its step while the client speculates. + pub fn pend(r: *Replica, ev: pardes.Event) ![]const u8 { r.stats.inputs += 1; const seq = r.next_seq; r.next_seq += 1; @@ -853,13 +863,18 @@ pub const Replica = struct { const msg = try r.gpa.dupe(u8, room[0 .. head_len + stamp_len + n]); try r.pending.append(r.gpa, .{ .seq = seq, .msg = msg, .sent_ns = nowNs(), .guess = g }); r.dirty = true; - r.settle(); - if (r.t.screen_state and r.diverged == null) r.echo.typed(r.core(), r.view, ev, seq, r.applied == r.pending.items.len); r.out.clearRetainingCapacity(); try r.out.appendSlice(r.gpa, msg); return r.out.items; } + /// An input's second half (`pend`'s, the last): applied at once when it + /// can be, its echo predicted. + pub fn applyPended(r: *Replica, ev: pardes.Event) void { + r.settle(); + if (r.t.screen_state and r.diverged == null) r.echo.typed(r.core(), r.view, ev, r.next_seq - 1, r.applied == r.pending.items.len); + } + /// One unit of the authority's stream, in its order. pub fn confirm(r: *Replica, msg: []const u8) void { if (r.diverged != null) return; @@ -3096,8 +3111,10 @@ pub const Link = struct { // Its notice read: a key of its own puts it away. if (c.notice_len > 0 and (ev == .key or ev == .paste)) c.notice_len = 0; c.input_ns = c.time(); - const msg = c.r.input(ev) catch return; + // Sent first: the session steps it while this replica speculates. + const msg = c.r.pend(ev) catch return; if (!sendInput(c.fd, msg)) c.cut(); + c.r.applyPended(ev); c.dirty = true; } |
