diff options
| -rw-r--r-- | test/perf.zig | 75 |
1 files changed, 72 insertions, 3 deletions
diff --git a/test/perf.zig b/test/perf.zig index 880e6abe..7920dedf 100644 --- a/test/perf.zig +++ b/test/perf.zig @@ -41,10 +41,17 @@ const Op = enum { open, render, key_down, + /// key_down's key through a near client and its session in one process + /// (`measureClient`): the pair's count. + client_key_down, key_right, page_down, wheel, edit_char, + client_edit_char, + /// A delete and its undo on the saved file (d, u: the terminal kit's + /// `edit`), through a near client and its session. + client_delete_undo, /// edit_char with a Zerox twin open on the same file: the twin takes /// the splice, not a copy of the text (File.setContentSpan). edit_twin, @@ -69,10 +76,13 @@ const Op = enum { .open => "open", .render => "render", .key_down => "key-down", + .client_key_down => "client-key-down", .key_right => "key-right", .page_down => "page-down", .wheel => "wheel", .edit_char => "edit-char", + .client_edit_char => "client-edit-char", + .client_delete_undo => "client-delete-undo", .edit_twin => "edit-twin", .body_write => "body-2m", .body_appends => "body-appends", @@ -565,7 +575,11 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u const samples = try gpa.alloc(u64, reps); defer gpa.free(samples); - if (op == .image_frame) return measureImage(std.fs.path.dirname(path).?, samples, warmup); + switch (op) { + .image_frame => return measureImage(std.fs.path.dirname(path).?, samples, warmup), + .client_key_down, .client_edit_char, .client_delete_undo => return measureClient(op, path, reps), + else => {}, + } if (op == .open) { for (0..warmup + reps) |n| { const core = try boot(); @@ -618,7 +632,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u const wheel_row = rect.y + pardes.BOX_H; const t0 = nowNs(); switch (op) { - .open, .image_frame => unreachable, + .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo => unreachable, .render, .deep_selection => {}, .key_down => core.update(.{ .key = .{ .cp = 'j', .text = "j" } }), .key_right => core.update(.{ .key = .{ .cp = 'l', .text = "l" } }), @@ -632,7 +646,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u _ = try frame(core); const dt = nowNs() -| t0; switch (op) { - .open, .image_frame => unreachable, + .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo => unreachable, .body_write => if (pane.file.?.content.len != before.len + 8 * body_chunk.len) return error.BodyWriteWasNotAppended, .body_appends => if (pane.file.?.content.len != before.len + append_count * append_chunk_len) return error.BodyAppendsWereNotAppended, .render, .deep_selection => if (pane.body.cur_row != before.row or pane.body.cur_col != before.col or pane.file.?.content.len != before.len) @@ -660,6 +674,61 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u return summarize(samples); } +/// The keys of a client cell's gesture: a key down, a character typed in +/// insert mode, a delete undone (two keys). +fn clientKeys(op: Op) []const pardes.Event { + return switch (op) { + .client_key_down => &.{.{ .key = .{ .cp = 'j', .text = "j" } }}, + .client_edit_char => &.{.{ .key = .{ .cp = 'x', .text = "x" } }}, + .client_delete_undo => &.{ .{ .key = .{ .cp = 'd', .text = "d" } }, .{ .key = .{ .cp = 'u', .text = "u" } } }, + else => unreachable, + }; +} + +const client_host_vtable = pardes.replica.everyEntry(.{}); + +/// A near client's gesture through a replica of a session in this process +/// (core/replica.zig), in the live pair's order: the key applied on the +/// client at once, the session's pump unit (it moved nothing) and the +/// key's own unit confirmed, the client's frame. The count is the pair's, +/// the session's step and the client's; one order of arrival, so what +/// depends on another (a unit of another client's, a late one) it does +/// not see. +fn measureClient(op: Op, path: []const u8, reps: usize) !Cell { + const warmup = 3; + const samples = try gpa.alloc(u64, reps); + defer gpa.free(samples); + const a = try pardes.replica.Authority.init(gpa, .{ .tty_only = true, .file = path, .cols = screen_cols, .rows = screen_rows }, .{ .vtable = &client_host_vtable }, false); + defer a.deinit(); + const r = try pardes.replica.Replica.init(gpa, 1, try a.unit(0, 0), false); + defer r.deinit(); + // Idle first, as a client is: its copy taken ahead and a pump's unit of + // the session's kept over it. Two units kept a key after that put the + // kept list's bound on a pump's unit, under a key applied: the arrival + // a client's rollback copy is dearest on (core/replica.zig keepSince). + r.ready(); + a.pump(); + r.confirm((try a.pending()).?); + if (op == .client_edit_char) try clientKey(a, r, .{ .key = .{ .cp = 'i', .text = "i" } }); + for (0..warmup + reps) |n| { + const t0 = nowNs(); + for (clientKeys(op)) |ev| try clientKey(a, r, ev); + _ = r.draw(.{ .ctx = null, .f = null }); + if (n >= warmup) samples[n - warmup] = (nowNs() -| t0) / 1000; + } + if (r.diverged != null or r.stats.mispredicted != 0 or !r.quiet() or r.digest() != pardes.replica.digestOf(a)) return error.ClientDiverged; + return summarize(samples); +} + +fn clientKey(a: *pardes.replica.Authority, r: *pardes.replica.Replica, ev: pardes.Event) !void { + const msg = try gpa.dupe(u8, try r.input(ev)); + defer gpa.free(msg); + a.pump(); + r.confirm((try a.pending()).?); + r.confirm(try a.take(msg)); + r.settle(); +} + fn measureImage(dir: []const u8, samples: []u64, warmup: usize) !Cell { const path = try std.fmt.allocPrint(gpa, "{s}/picture.ppm", .{dir}); defer gpa.free(path); |
