summaryrefslogtreecommitdiff
path: root/test/perf.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 17:35:06 -0300
committerGabriel Schneider <[email protected]>2026-10-30 17:35:06 -0300
commit6d8da8721141284cf33bb901168b26135893eb86 (patch)
tree791d63401d4e85fbca1d597a8ce0326e70efd545 /test/perf.zig
parentefd43a3a2cf03bb741366331158b368abf9ac583 (diff)
parentbf6810a8f9d6cc82050e7d9c0cfb06358301b574 (diff)
downloadpardes-6d8da8721141284cf33bb901168b26135893eb86.tar.gz
pardes-6d8da8721141284cf33bb901168b26135893eb86.zip
Merge latest upstream into the macOS branch for Zig 0.17
Retain the macOS branch history and local Acme selection color while adopting upstream's current core and platform changes. Pin Zig and ZLS to 0.17.0, and fetch the existing zstbi compatibility commit through upstream after its original fork was removed.
Diffstat (limited to 'test/perf.zig')
-rw-r--r--test/perf.zig387
1 files changed, 300 insertions, 87 deletions
diff --git a/test/perf.zig b/test/perf.zig
index 5aa5c4d4..ab284739 100644
--- a/test/perf.zig
+++ b/test/perf.zig
@@ -46,6 +46,20 @@ const Op = enum {
page_down,
wheel,
edit_char,
+ /// 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,
+ /// 2 MB appended to the file through 9P, on one open, in 256 KB
+ /// writes: linear, not a copy of the whole buffer per write.
+ body_write,
+ /// 64 appends to the file through 9P, each its own open, 8 KB write and
+ /// close, as a shell's `>>` loop makes: each costs its own bytes, not a
+ /// pass over the whole body for its cursor, line index and saved hash.
+ body_appends,
+ /// A render with the selection 2 MB into one line: only the columns
+ /// shown are measured, so it costs what a selection at the line's
+ /// start does (4.5 s a frame at 5 MB before).
+ deep_selection,
fn label(o: Op) []const u8 {
return switch (o) {
@@ -56,10 +70,52 @@ const Op = enum {
.page_down => "page-down",
.wheel => "wheel",
.edit_char => "edit-char",
+ .edit_twin => "edit-twin",
+ .body_write => "body-2m",
+ .body_appends => "body-appends",
+ .deep_selection => "deep-sel",
};
}
};
+var body_chunk: [256 * 1024]u8 = @splat('y');
+
+/// The body_write gesture: an open of the pane's body, eight 256 KB writes,
+/// a read (which the held writes go in before), the close.
+fn bodyWrite(core: *pardes.Pardes, serial: u32) void {
+ const Node = pardes.ctlfs.Node;
+ const body = Node.of(serial, .body);
+ for (&body_chunk, 0..) |*c, i| c.* = if (i % 64 == 63) '\n' else 'y';
+ const h = core.serveFs(.{ .tag = 1, .op = .open, .node = body, .omode = 1 }).handle;
+ for (0..8) |_| _ = core.serveFs(.{ .tag = 2, .op = .write, .node = body, .handle = h, .data = &body_chunk });
+ _ = core.serveFs(.{ .tag = 3, .op = .getattr, .node = body, .handle = h });
+ _ = core.serveFs(.{ .tag = 4, .op = .release, .node = body, .handle = h, .opened = true });
+}
+
+/// One line of 2 MB appended to the file, no newline in it.
+fn longLine(core: *pardes.Pardes, serial: u32) void {
+ const Node = pardes.ctlfs.Node;
+ const body = Node.of(serial, .body);
+ @memset(&body_chunk, 'z');
+ const h = core.serveFs(.{ .tag = 1, .op = .open, .node = body, .omode = 1 }).handle;
+ for (0..8) |_| _ = core.serveFs(.{ .tag = 2, .op = .write, .node = body, .handle = h, .data = &body_chunk });
+ _ = core.serveFs(.{ .tag = 4, .op = .release, .node = body, .handle = h, .opened = true });
+}
+
+const append_chunk_len = 8 * 1024;
+const append_count = 64;
+
+fn bodyAppends(core: *pardes.Pardes, serial: u32) void {
+ const Node = pardes.ctlfs.Node;
+ const body = Node.of(serial, .body);
+ for (body_chunk[0..append_chunk_len], 0..) |*c, i| c.* = if (i % 64 == 63) '\n' else 'y';
+ for (0..append_count) |_| {
+ const h = core.serveFs(.{ .tag = 1, .op = .open, .node = body, .omode = 1 }).handle;
+ _ = core.serveFs(.{ .tag = 2, .op = .write, .node = body, .handle = h, .data = body_chunk[0..append_chunk_len] });
+ _ = core.serveFs(.{ .tag = 4, .op = .release, .node = body, .handle = h, .opened = true });
+ }
+}
+
const TermFixture = struct {
name: []const u8,
kb: usize,
@@ -151,6 +207,93 @@ const Allocations = struct {
}
};
+/// What a session costs before it can show anything: the core's own boot, then
+/// the first frame built from it. The host's share — process spawn, dynamic
+/// linking, GPU and font setup — is not in here and has to be timed around the
+/// real binary; this is the half that a change to the editor can move.
+fn measureStartup(io: std.Io, reps: usize, json: bool) !void {
+ if (reps == 0 or screen_cols == 0 or screen_rows == 0) return error.InvalidMeasurement;
+ const init_samples = try gpa.alloc(u64, reps);
+ defer gpa.free(init_samples);
+ const frame_samples = try gpa.alloc(u64, reps);
+ defer gpa.free(frame_samples);
+
+ const cases = [_]struct { name: []const u8, boot: pardes.Boot }{
+ .{ .name = "startup-tty", .boot = .tty },
+ .{ .name = "startup-tty-shell", .boot = .tty_shell },
+ .{ .name = "startup-shell", .boot = .shell },
+ .{ .name = "startup-classic", .boot = .classic },
+ };
+ for (cases) |case| {
+ if (!pardes.terminal_panes) continue;
+ var cold_ns: u64 = 0;
+ var calls: usize = 0;
+ var bytes: usize = 0;
+ var peak: usize = 0;
+ for (0..reps + 1) |index| {
+ var counter: Allocations = .{};
+ const allocator = counter.allocator();
+ const begin = nowNs();
+ const core = try pardes.Pardes.init(allocator, .{
+ .tty_only = case.boot == .tty or case.boot == .tty_shell,
+ .boot = case.boot,
+ .shells = if (case.boot == .classic) 3 else 1,
+ .cols = screen_cols,
+ .rows = screen_rows,
+ });
+ const booted = nowNs();
+ var paint = std.heap.ArenaAllocator.init(allocator);
+ _ = try core.render(paint.allocator());
+ const painted = nowNs();
+ paint.deinit();
+ core.deinit();
+ if (index == 0) {
+ cold_ns = booted - begin;
+ } else {
+ init_samples[index - 1] = booted - begin;
+ frame_samples[index - 1] = painted - booted;
+ calls += counter.calls;
+ bytes += counter.bytes;
+ peak = @max(peak, counter.peak);
+ }
+ // Every other measurement in this file checks the session gave
+ // everything back; a boot that leaks is exactly what a startup
+ // benchmark should be the first to notice.
+ if (counter.live != 0) return error.LeakedStartupMemory;
+ }
+ std.mem.sort(u64, init_samples, {}, std.sort.asc(u64));
+ std.mem.sort(u64, frame_samples, {}, std.sort.asc(u64));
+ const result = .{
+ .build = build_identity,
+ .harness = harness_id,
+ .case = case.name,
+ .cols = screen_cols,
+ .rows = screen_rows,
+ .reps = reps,
+ .cold_ns = cold_ns,
+ .init_median_ns = init_samples[reps / 2],
+ // A p95 needs at least twenty samples to be one; below that this
+ // is the maximum and says so rather than dressing it up.
+ .init_p95_ns = if (reps >= 20) init_samples[reps * 95 / 100] else init_samples[reps - 1],
+ .init_max_ns = init_samples[reps - 1],
+ .frame_median_ns = frame_samples[reps / 2],
+ .allocations = calls / reps,
+ .allocated_bytes = bytes / reps,
+ .peak_bytes = peak,
+ };
+ const text = if (json)
+ try std.json.Stringify.valueAlloc(gpa, result, .{})
+ else
+ try std.fmt.allocPrint(gpa, "{s}: boot {d} ns (cold {d}), first frame {d} ns, {d} allocations / {d} B, peak {d} B", .{
+ result.case, result.init_median_ns, result.cold_ns, result.frame_median_ns,
+ result.allocations, result.allocated_bytes, result.peak_bytes,
+ });
+ defer gpa.free(text);
+ try std.Io.File.stdout().writeStreamingAll(io, text);
+ try std.Io.File.stdout().writeStreamingAll(io, "\n");
+ }
+}
+
fn measureCreation(io: std.Io, reps: usize, json: bool) !void {
if (reps == 0 or screen_cols == 0 or screen_rows == 0) return error.InvalidMeasurement;
const samples = try gpa.alloc(u64, reps);
@@ -170,12 +313,12 @@ fn measureCreation(io: std.Io, reps: usize, json: bool) !void {
const allocator = counter.allocator();
const begin = nowNs();
const pane = if (terminal)
- try pardes.panes.Terminal.create(allocator, screen_cols, screen_rows)
+ try pardes.panes.terminal.create(allocator, screen_cols, screen_rows)
else
- try pardes.panes.Terminal.createDoc(allocator, screen_cols, screen_rows);
+ try pardes.panes.terminal.createDoc(allocator, screen_cols, screen_rows);
const constructed = nowNs();
const retained = counter.live;
- pardes.panes.Terminal.deinitEmulator(pane, allocator);
+ pardes.panes.terminal.deinitEmulator(pane, allocator);
allocator.destroy(pane);
const destroyed = nowNs();
if (counter.live != 0) return error.LeakedPaneMemory;
@@ -232,9 +375,13 @@ const Options = struct {
base: ?[]const u8 = null,
only: ?[]const u8 = null,
creation: bool = false,
+ startup: bool = false,
mini: bool = false,
terminal_mib: ?usize = null,
self_test: bool = false,
+ /// A gate: fail when a cell's fastest sample is more than this many
+ /// times the baseline's fastest (--base's).
+ max_ratio: ?f64 = null,
fn parse(args: []const []const u8) !Options {
var opts: Options = .{};
@@ -242,11 +389,12 @@ const Options = struct {
while (i < args.len) : (i += 1) {
const arg = args[i];
if (!std.mem.startsWith(u8, arg, "--")) return error.UnknownOption;
- const option = std.meta.stringToEnum(enum { json, creation, mini, @"terminal-mib", @"self-test", reps, cols, rows, base, only }, arg[2..]) orelse
+ const option = std.meta.stringToEnum(enum { json, creation, startup, mini, @"terminal-mib", @"self-test", reps, cols, rows, base, only, @"max-ratio" }, arg[2..]) orelse
return error.UnknownOption;
switch (option) {
.json => opts.json = true,
.creation => opts.creation = true,
+ .startup => opts.startup = true,
.mini => opts.mini = true,
.@"self-test" => opts.self_test = true,
else => {
@@ -260,6 +408,7 @@ const Options = struct {
.base => opts.base = value,
.only => opts.only = value,
.@"terminal-mib" => opts.terminal_mib = std.fmt.parseInt(usize, value, 10) catch return error.InvalidNumber,
+ .@"max-ratio" => opts.max_ratio = std.fmt.parseFloat(f64, value) catch return error.InvalidNumber,
else => unreachable,
}
},
@@ -274,6 +423,10 @@ const Options = struct {
if (opts.creation or opts.only != null or opts.base != null) return error.IncompatibleOptions;
}
if (opts.base) |path| if (path.len == 0) return error.MissingValue;
+ if (opts.max_ratio) |ratio| {
+ if (opts.base == null) return error.IncompatibleOptions;
+ if (!(ratio >= 1)) return error.InvalidMeasurement;
+ }
if (opts.mini and (opts.creation or opts.terminal_mib != null or opts.only != null or opts.base != null))
return error.IncompatibleOptions;
if (opts.only) |name| {
@@ -295,6 +448,7 @@ pub fn main(init: std.process.Init) !void {
screen_rows = opts.rows;
const reps = opts.reps;
const only = opts.only;
+ if (opts.startup) return measureStartup(init.io, reps, opts.json);
if (opts.creation) return measureCreation(init.io, reps, opts.json);
if (opts.terminal_mib) |mib| return measureTerminalSession(init.io, mib, reps, opts.json);
if (opts.mini) return measureMini(init.io, init.gpa, reps, opts.json);
@@ -341,8 +495,41 @@ pub fn main(init: std.process.Init) !void {
}
}
- if (opts.json) return reportJson(init.io, &cells, &term_cells, &bytes, opts);
- reportText(&cells, &term_cells, &bytes, reps, opts.base, base);
+ if (opts.json) try reportJson(init.io, &cells, &term_cells, &bytes, opts) else reportText(&cells, &term_cells, &bytes, reps, opts.base, base);
+ if (opts.max_ratio) |ratio| try gate(&cells, &base.?, ratio);
+}
+
+/// The performance gate (zig build perf-gate): every measured cell's
+/// fastest sample against the baseline's fastest. The fastest, not the
+/// median: a loaded machine slows the median, rarely the best of a run,
+/// while a regression slows every sample.
+fn gate(cells: *const [std.enums.values(Op).len][fixtures.len]Cell, base: *const Base, ratio: f64) !void {
+ var failed = false;
+ for (std.enums.values(Op), 0..) |op, oi| for (fixtures, 0..) |fx, fi| {
+ const then = base.min[oi][fi];
+ const now = cells[oi][fi].min_us;
+ if (then == 0 or now == 0) continue;
+ const x = @as(f64, @floatFromInt(now)) / @as(f64, @floatFromInt(then));
+ if (x > ratio) {
+ std.debug.print("perf gate: {s} on {s} took {d} us at best, {d:.1}x the baseline's {d} us (limit {d:.1}x)\n", .{ op.label(), fx.name, now, x, then, ratio });
+ failed = true;
+ }
+ };
+ // Typing beside a twin costs about what typing alone does, whatever the
+ // baseline: the twin takes the splice, never a copy of the text.
+ const twin_op = @backingInt(Op.edit_twin);
+ const alone_op = @backingInt(Op.edit_char);
+ for (fixtures, 0..) |fx, fi| {
+ const twin = cells[twin_op][fi].min_us;
+ const alone = cells[alone_op][fi].min_us;
+ if (twin == 0 or alone == 0) continue;
+ if (@as(f64, @floatFromInt(twin)) > ratio * @as(f64, @floatFromInt(alone))) {
+ std.debug.print("perf gate: edit-twin on {s} took {d} us at best, over {d:.1}x edit-char's {d} us\n", .{ fx.name, twin, ratio, alone });
+ failed = true;
+ }
+ }
+ if (failed) return error.PerformanceRegression;
+ std.debug.print("perf gate: every cell within {d:.1}x of the baseline\n", .{ratio});
}
fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: usize) !Cell {
@@ -355,7 +542,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u
const core = try boot();
defer core.deinit();
const t0 = nowNs();
- core.lookAt(0, path);
+ pardes.look.lookAt(core, 0, path);
pump(core);
_ = try frame(core);
const dt = nowNs() -| t0;
@@ -369,52 +556,74 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u
const core = try boot();
defer core.deinit();
- core.lookAt(0, path);
+ pardes.look.lookAt(core, 0, path);
pump(core);
const id = filePane(core) orelse return error.OpenDidNotOpenFile;
core.active = id;
const pane = core.panes[id].?;
_ = try frame(core);
- if (op == .edit_char) {
+ if (op == .edit_twin) {
+ if (!core.executeBuiltinLine(id, "Zerox")) return error.ZeroxRefused;
+ pump(core);
+ core.active = id;
+ _ = try frame(core);
+ }
+ if (op == .edit_char or op == .edit_twin) {
core.update(.{ .key = .{ .cp = 'i', .text = "i" } });
pump(core);
}
+ if (op == .deep_selection) {
+ longLine(core, pane.serial);
+ pump(core);
+ const len: u32 = @intCast(pane.file.?.content.len);
+ pardes.ctlfs.pane.setDot(pane, .{ .q0 = len - 10, .q1 = len - 5 });
+ pump(core);
+ }
for (0..warmup + reps) |n| {
- seek(pane, fx, n);
+ if (op != .deep_selection) seek(pane, fx, n);
_ = try frame(core); // settle the view at the new spot, untimed
- const before = .{ .row = pane.cur_row, .col = pane.cur_col, .scroll = pane.scroll(), .len = pane.file.?.content.len };
+ const before = .{ .row = pane.body.cur_row, .col = pane.body.cur_col, .scroll = pane.scroll(), .len = pane.file.?.content.len };
const rect = core.rects[id];
const wheel_col = rect.x + pardes.config.GUTTER;
const wheel_row = if (core.settings.tag_bottom) rect.y else rect.y + pardes.BOX_H;
const t0 = nowNs();
switch (op) {
.open => unreachable,
- .render => {},
+ .render, .deep_selection => {},
.key_down => core.update(.{ .key = .{ .cp = 'j', .text = "j" } }),
.key_right => core.update(.{ .key = .{ .cp = 'l', .text = "l" } }),
.page_down => core.update(.{ .key = .{ .cp = pardes.Key.page_down } }),
.wheel => core.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = wheel_col, .row = wheel_row } }),
- .edit_char => core.update(.{ .key = .{ .cp = 'x', .text = "x" } }),
+ .edit_char, .edit_twin => core.update(.{ .key = .{ .cp = 'x', .text = "x" } }),
+ .body_write => bodyWrite(core, pane.serial),
+ .body_appends => bodyAppends(core, pane.serial),
}
pump(core);
_ = try frame(core);
const dt = nowNs() -| t0;
switch (op) {
.open => unreachable,
- .render => if (pane.cur_row != before.row or pane.cur_col != before.col or pane.file.?.content.len != before.len)
+ .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)
return error.RenderChangedDocument,
- .key_down => if (pane.cur_row != before.row + 1) return error.DownDidNotMove,
- .key_right => if (pane.cur_row != before.row or pane.cur_col != before.col + 1) return error.RightDidNotMove,
+ .key_down => if (pane.body.cur_row != before.row + 1) return error.DownDidNotMove,
+ .key_right => if (pane.body.cur_row != before.row or pane.body.cur_col != before.col + 1) return error.RightDidNotMove,
.page_down => if (pane.scroll() <= before.scroll and before.scroll < @as(i32, @intCast(fx.lines)) - pane.rows)
return error.PageDidNotScroll,
.wheel => if (pane.scroll() <= before.scroll and before.scroll < @as(i32, @intCast(fx.lines)) - pane.rows)
return error.WheelDidNotScroll,
- .edit_char => {
- if (pane.file.?.content.len != before.len + 1 or pane.cur_row != before.row or pane.cur_col != before.col + 1)
+ .edit_char, .edit_twin => {
+ if (pane.file.?.content.len != before.len + 1 or pane.body.cur_row != before.row or pane.body.cur_col != before.col + 1)
return error.CharacterWasNotInserted;
const line = pardes.panes.File.sourceLine(pane, before.row);
if (line[@intCast(before.col)] != 'x') return error.CharacterWasNotInserted;
+ if (op == .edit_twin) for (core.panes, 0..) |slot, other| {
+ const twin = slot orelse continue;
+ if (other == id or twin.file == null or twin.file.?.twin != pane.file.?.twin) continue;
+ if (twin.file.?.content.ptr != pane.file.?.content.ptr) return error.TwinMissedTheEdit;
+ } else if (pane.file.?.twin == 0) return error.NoTwin;
},
}
if (n >= warmup) samples[n - warmup] = dt / 1000;
@@ -431,13 +640,13 @@ fn measureTerm(op: TermOp, fx: TermFixture, reps: usize) !Cell {
defer core.deinit();
const pane = core.panes[0] orelse return error.MissingTerminal;
const state = pane.terminal orelse return error.MissingTerminal;
- if (op == .key_down or op == .edit_char) pane.mode = .normal;
+ if (op == .key_down or op == .edit_char) pane.body.mode = .normal;
if (op == .edit_char) {
core.update(.{ .key = .{ .cp = 'i', .text = "i" } });
pump(core);
}
_ = try frame(core);
- const motion_rows = if (op == .key_down) (try core.paneCursorLines(pane)).len else 0;
+ const motion_rows = if (op == .key_down) (try pardes.edit.paneCursorLines(core, &pane.body)).len else 0;
if (op == .key_down and motion_rows < 3) return error.EmptyTerminalFixture;
var cols = screen_cols;
@@ -445,19 +654,17 @@ fn measureTerm(op: TermOp, fx: TermFixture, reps: usize) !Cell {
for (0..warmup + reps) |n| {
if (op == .key_down) {
const span = @max(1, motion_rows * 8 / 10);
- pane.cur_row = @intCast(@min(motion_rows - 2, motion_rows / 10 + (n *% 7919) % span));
- pane.cur_col = 0;
- pane.cur_pinned = true;
- pane.sticky_col = -1;
+ pane.body.cur_row = @intCast(@min(motion_rows - 2, motion_rows / 10 + (n *% 7919) % span));
+ pane.body.cur_col = 0;
+ pane.body.cur_pinned = true;
+ pane.body.sticky_col = -1;
pane.ensureCursorVisible();
_ = try frame(core);
}
const before = .{
- .row = pane.cur_row,
- .col = pane.cur_col,
+ .row = pane.body.cur_row,
+ .col = pane.body.cur_col,
.edit_len = if (pane.ovl) |overlay| overlay.text.len else 0,
- .replay_head = state.replay.head,
- .replay_len = state.replay.len,
.cols = pane.cols,
.rows = pane.rows,
};
@@ -480,32 +687,21 @@ fn measureTerm(op: TermOp, fx: TermFixture, reps: usize) !Cell {
_ = try frame(core);
const dt = nowNs() -| t0;
switch (op) {
- .render => if (pane.cur_row != before.row or pane.cur_col != before.col or
- state.replay.head != before.replay_head or state.replay.len != before.replay_len)
+ .render => if (pane.body.cur_row != before.row or pane.body.cur_col != before.col)
return error.RenderChangedTerminal,
- .output => {
- const capacity = state.replay.bytes.len;
- if (term_chunk.len == 0 or term_chunk.len >= capacity) return error.InvalidOutputFixture;
- const overflow = term_chunk.len -| (capacity - before.replay_len);
- if (state.replay.len != @min(capacity, before.replay_len + term_chunk.len) or
- state.replay.head != (before.replay_head + overflow) % capacity)
- return error.OutputWasNotRecorded;
- const start = (state.replay.head + state.replay.len - term_chunk.len) % capacity;
- const first = @min(term_chunk.len, capacity - start);
- if (!std.mem.eql(u8, term_chunk[0..first], state.replay.bytes[start..][0..first]) or
- !std.mem.eql(u8, term_chunk[first..], state.replay.bytes[0 .. term_chunk.len - first]))
- return error.WrongTerminalOutput;
- },
+ // What the output did to the screen is the snapshot suite's to
+ // check; here it is timed.
+ .output => if (term_chunk.len == 0) return error.InvalidOutputFixture,
.resize_rows => if (pane.rows == before.rows or pane.cols != before.cols or
state.vt.screens.active.pages.rows != pane.rows) return error.TerminalDidNotResize,
.resize_cols => if (pane.cols == before.cols or pane.rows != before.rows or
state.vt.screens.active.pages.cols != pane.cols) return error.TerminalDidNotResize,
- .key_down => if (pane.cur_row != before.row + 1) return error.DownDidNotMove,
+ .key_down => if (pane.body.cur_row != before.row + 1) return error.DownDidNotMove,
.edit_char => {
const overlay = pane.ovl orelse return error.CharacterWasNotInserted;
- if (overlay.text.len != before.edit_len + 1 or pane.cur_row != before.row or pane.cur_col != before.col + 1)
+ if (overlay.text.len != before.edit_len + 1 or pane.body.cur_row != before.row or pane.body.cur_col != before.col + 1)
return error.CharacterWasNotInserted;
- const line = pardes.modal.lineSlice(overlay.text, @intCast(pane.cur_row - overlay.row));
+ const line = pardes.modal.lineSlice(overlay.text, @intCast(pane.body.cur_row - overlay.row));
if (before.col < 0 or before.col >= line.len or line[@intCast(before.col)] != 'x')
return error.CharacterWasNotInserted;
},
@@ -569,7 +765,7 @@ fn checkTerminalTail(core: *pardes.Pardes, surface: *pardes.Surface, batch: usiz
const pane = core.panes[0] orelse return error.MissingTerminal;
const rect = core.rects[0];
const x = rect.x + pardes.config.GUTTER;
- const y = (if (core.settings.tag_bottom) rect.y else rect.y + pardes.BOX_H) + pardes.panes.Terminal.gridCursor(pane).y;
+ const y = (if (core.settings.tag_bottom) rect.y else rect.y + pardes.BOX_H) + pardes.panes.terminal.gridCursor(pane).y;
var expected_buffer: [32]u8 = undefined;
const expected = try std.fmt.bufPrint(&expected_buffer, "TURN {d:0>10} READY", .{batch});
for (expected, 0..) |byte, col| {
@@ -621,7 +817,7 @@ const UndoOutput = struct {
fn measureUndoOutput(core: *pardes.Pardes, counter: *Allocations, arena: *std.heap.ArenaAllocator, samples: []u64) ![3]UndoOutput {
const pane = core.panes[0].?;
const pages = &pane.terminal.?.vt.screens.active.pages;
- if (pane.ed_undo_len != 0 or pane.ed_redo_len != 0) return error.UnexpectedTerminalHistory;
+ if (pane.body.ed_undo_len != 0 or pane.body.ed_redo_len != 0) return error.UnexpectedTerminalHistory;
if (pane.ovl) |overlay| core.gpa.free(overlay.text);
pane.ovl = null;
var result: [3]UndoOutput = undefined;
@@ -632,19 +828,19 @@ fn measureUndoOutput(core: *pardes.Pardes, counter: *Allocations, arena: *std.he
const first: i32 = @intCast(@min(128, pages.total_rows - 2));
for (0..depth) |index| {
pane.ovl = .{ .row = first, .rows = 2, .text = try std.fmt.allocPrint(core.gpa, "saved edit {d}\nsecond row", .{index}) };
- pane.cur_row = first + 1;
- pane.cur_col = 1;
- pane.vsel = .{ .active = true, .row = first, .col = 0 };
- pardes.panes.Terminal.pushUndo(core, pane);
+ pane.body.cur_row = first + 1;
+ pane.body.cur_col = 1;
+ pane.body.vsel = .{ .active = true, .row = first, .col = 0 };
+ pardes.panes.terminal.pushUndo(core, pane);
core.gpa.free(pane.ovl.?.text);
pane.ovl = null;
- if (pane.ed_undo_len != index + 1) return error.TerminalUndoSnapshotFailed;
+ if (pane.body.ed_undo_len != index + 1) return error.TerminalUndoSnapshotFailed;
}
defer {
- for (pane.ed_undo[0..pane.ed_undo_len]) |snapshot| if (snapshot.ovl) |overlay| core.gpa.free(overlay.text);
- pane.ed_undo_len = 0;
+ for (pane.body.ed_undo[0..pane.body.ed_undo_len]) |snapshot| if (snapshot.ovl) |overlay| core.gpa.free(overlay.text);
+ pane.body.ed_undo_len = 0;
}
- pardes.panes.Terminal.enterTty(core, 0);
+ pardes.panes.terminal.enterTty(core, 0);
pump(core);
const tracked_before = pages.countTrackedPins();
const start = try pages.trackPin(pages.pin(.{ .screen = .{ .y = @intCast(first) } }).?);
@@ -677,7 +873,7 @@ fn measureUndoOutput(core: *pardes.Pardes, counter: *Allocations, arena: *std.he
if (pages.countTrackedPins() != tracked_before + 2) return error.TerminalPinsLeaked;
const expected: i32 = if (start.garbage) 0 else @intCast((pages.pointFromPin(.screen, start.*) orelse return error.TerminalAnchorLost).screen.y);
const last: i32 = if (end.garbage) 0 else @intCast((pages.pointFromPin(.screen, end.*) orelse return error.TerminalAnchorLost).screen.y);
- for (pane.ed_undo[0..pane.ed_undo_len], 0..) |snapshot, index| {
+ for (pane.body.ed_undo[0..pane.body.ed_undo_len], 0..) |snapshot, index| {
const overlay = snapshot.ovl orelse return error.TerminalUndoTextLost;
var expected_buffer: [64]u8 = undefined;
const text = try std.fmt.bufPrint(&expected_buffer, "saved edit {d}\nsecond row", .{index});
@@ -722,7 +918,7 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void
pump(core);
const pane = core.panes[0] orelse return error.MissingTerminal;
const state = pane.terminal orelse return error.MissingTerminal;
- pane.mode = .tty;
+ pane.body.mode = .tty;
pane.tty_filter = false;
var arena: std.heap.ArenaAllocator = .init(counter.allocator());
defer arena.deinit();
@@ -757,7 +953,7 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void
}
const stream_wall_ns = nowNs() - stream_begin;
const live_after_output = counter.live;
- const first_row = @as(i32, @intCast(state.vt.screens.active.pages.scrollbar().offset)) + @as(i32, pardes.panes.Terminal.gridCursor(pane).y);
+ const first_row = @as(i32, @intCast(state.vt.screens.active.pages.scrollbar().offset)) + @as(i32, pardes.panes.terminal.gridCursor(pane).y);
_ = arena.reset(.retain_capacity);
const modal_begin = nowNs();
core.update(.{ .key = .{ .cp = core.opts.tty_toggle, .ctrl = true } });
@@ -765,17 +961,17 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void
pump(core);
_ = try core.render(arena.allocator());
const first_modal_ns = nowNs() - modal_begin;
- if (pane.mode != .normal or !pane.cur_pinned or pane.cur_row != first_row - 1) return error.FirstModalKeyDidNotMove;
+ if (pane.body.mode != .normal or !pane.body.cur_pinned or pane.body.cur_row != first_row - 1) return error.FirstModalKeyDidNotMove;
for (modal_samples, 0..) |*sample, index| {
const down = index % 2 == 0;
- const before = pane.cur_row;
+ const before = pane.body.cur_row;
_ = arena.reset(.retain_capacity);
const begin = nowNs();
core.update(.{ .key = .{ .cp = if (down) 'j' else 'k' } });
pump(core);
_ = try core.render(arena.allocator());
sample.* = nowNs() - begin;
- if (pane.cur_row != before + @as(i32, if (down) 1 else -1)) return error.ModalKeyDidNotMove;
+ if (pane.body.cur_row != before + @as(i32, if (down) 1 else -1)) return error.ModalKeyDidNotMove;
}
core.update(.{ .key = .{ .cp = core.opts.tty_toggle, .ctrl = true } });
pump(core);
@@ -793,8 +989,8 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void
const live_after_modal = counter.live;
var overlay_median_ns: [2]u64 = undefined;
var overlay_p95_ns: [2]u64 = undefined;
- pane.mode = .normal;
- pane.cur_pinned = true;
+ pane.body.mode = .normal;
+ pane.body.cur_pinned = true;
pane.ovl = .{ .row = 0, .rows = 1, .text = try core.gpa.dupe(u8, "edited output") };
for (0..2) |phase| {
for (modal_samples, 0..) |*sample, index| {
@@ -805,10 +1001,10 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void
const begin = nowNs();
core.update(.{ .output = .{ .pane = 0, .bytes = update } });
pump(core);
- const cursor_row = pardes.panes.Terminal.gridOffset(pane) + @as(i32, pardes.panes.Terminal.gridCursor(pane).y);
+ const cursor_row = pardes.panes.terminal.gridOffset(pane) + @as(i32, pardes.panes.terminal.gridCursor(pane).y);
pane.ovl.?.row = if (phase == 0) 0 else cursor_row - 1;
- pane.cur_row = pane.ovl.?.row;
- pane.cur_col = 0;
+ pane.body.cur_row = pane.ovl.?.row;
+ pane.body.cur_col = 0;
const surface = try core.render(arena.allocator());
sample.* = nowNs() - begin;
try checkTerminalTail(core, surface, tail_id);
@@ -845,7 +1041,7 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void
.undo_output = undo_output,
.history_rows = state.vt.screens.active.pages.scrollbar().total,
.history_bytes = state.vt.screens.active.pages.page_size,
- .history_limit_bytes = state.vt.screens.active.pages.maxSize(),
+ .history_limit_bytes = state.vt.screens.active.pages.limits.max(.bytes),
.row_count_decreases = row_count_decreases,
.allocator_calls = counter.calls,
.allocator_live_after_output = live_after_output,
@@ -885,12 +1081,12 @@ const MiniMeasurement = struct {
live_after_deinit: usize = 0,
};
-fn checkMini(actual: pardes.panes.Mini.Result, expected: pardes.panes.Mini.Result) !void {
+fn checkMini(actual: pardes.panes.mini.Result, expected: pardes.panes.mini.Result) !void {
if (!std.mem.eql(u8, actual.content, expected.content) or !std.mem.eql(u8, actual.colors, expected.colors))
return error.MiniOutputMismatch;
}
-fn miniMeasurement(fallback: std.mem.Allocator, probe: MiniProbe, path: []const u8, source: []const u8, styles: []const u8, expected: pardes.panes.Mini.Result, reps: usize) !MiniMeasurement {
+fn miniMeasurement(fallback: std.mem.Allocator, probe: MiniProbe, path: []const u8, source: []const u8, styles: []const u8, expected: pardes.panes.mini.Result, reps: usize) !MiniMeasurement {
const samples = try gpa.alloc(u64, reps);
defer gpa.free(samples);
const allocators = pardes.memory.init(fallback);
@@ -921,8 +1117,8 @@ fn miniMeasurement(fallback: std.mem.Allocator, probe: MiniProbe, path: []const
defer arena.deinit();
if (core) |p| {
pump(p);
- try pardes.panes.Mini.open(p, 0, path);
- for (p.panes, 0..) |slot, id| if (slot != null and id != p.active) try p.removePane(id);
+ try pardes.panes.mini.open(p, 0, path);
+ for (p.panes, 0..) |slot, id| if (slot != null and id != p.active) try p.removePane(id, null);
pump(p);
p.settings.colors = true;
const file = p.panes[p.active].?.file.?;
@@ -957,7 +1153,7 @@ fn miniMeasurement(fallback: std.mem.Allocator, probe: MiniProbe, path: []const
else
styles;
defer if (probe == .highlight_generate) syntax_allocator.free(highlighted);
- const converted = try pardes.panes.Mini.generate(allocator, source, highlighted);
+ const converted = try pardes.panes.mini.generate(allocator, source, highlighted);
const elapsed = nowNs() - begin;
defer converted.deinit(allocator);
if (index == 0) result.cold_ns = elapsed else samples[index - 1] = elapsed;
@@ -1011,9 +1207,9 @@ fn measureMini(io: std.Io, fallback: std.mem.Allocator, reps: usize, json: bool)
break :blk try pardes.syntax.highlightFileRange(gpa, path, source, 0, source.len);
};
defer gpa.free(styles);
- if (styles.len != source.len or std.mem.indexOfScalar(u8, styles, @intFromEnum(pardes.syntax.Syn.comment)) == null)
+ if (styles.len != source.len or std.mem.indexOfScalar(u8, styles, @backingInt(pardes.syntax.Syn.comment)) == null)
return error.MiniSyntaxUnavailable;
- const expected = try pardes.panes.Mini.generate(gpa, source, styles);
+ const expected = try pardes.panes.mini.generate(gpa, source, styles);
defer expected.deinit(gpa);
if (expected.content.len == 0 or expected.content.len != expected.colors.len or !std.unicode.utf8ValidateSlice(expected.content))
return error.InvalidMiniOutput;
@@ -1056,11 +1252,11 @@ fn seek(pane: *pardes.Pane, fx: Fixture, n: usize) void {
const row = fx.lines / 10 + (n *% 7919) % span;
f.scroll = @min(row, fx.lines -| 1);
f.syntax_dirty = true;
- pane.cur_row = @intCast(f.scroll);
- pane.cur_col = if (fx.cols > 200) @intCast(fx.cols * 3 / 4) else 0;
- pane.cur_pinned = true;
- pane.hscroll = @max(0, pane.cur_col - 40);
- pane.sticky_col = -1;
+ pane.body.cur_row = @intCast(f.scroll);
+ pane.body.cur_col = if (fx.cols > 200) @intCast(fx.cols * 3 / 4) else 0;
+ pane.body.cur_pinned = true;
+ pane.hscroll = @max(0, pane.body.cur_col - 40);
+ pane.body.sticky_col = -1;
}
fn boot() !*pardes.Pardes {
@@ -1176,7 +1372,7 @@ fn reportText(
for (fixtures) |fx| {
if (base != null) o(" {s:>19}", .{fx.name}) else o(" {s:>12}", .{fx.name});
}
- o("\n{s}\n", .{if (base != null) "-" ** (12 + fixtures.len * 20) else "-" ** (12 + fixtures.len * 13)});
+ o("\n{s}\n", .{if (base != null) &@as([12 + fixtures.len * 20]u8, @splat('-')) else &@as([12 + fixtures.len * 13]u8, @splat('-'))});
var worst_jitter: f64 = 0;
for (std.enums.values(Op), 0..) |op, oi| {
o("{s:<12}", .{op.label()});
@@ -1203,7 +1399,7 @@ fn reportText(
for (term_fixtures) |fx| {
if (base != null) o(" {s:>19}", .{fx.name}) else o(" {s:>12}", .{fx.name});
}
- o("\n{s}\n", .{if (base != null) "-" ** (12 + term_fixtures.len * 20) else "-" ** (12 + term_fixtures.len * 13)});
+ o("\n{s}\n", .{if (base != null) &@as([12 + term_fixtures.len * 20]u8, @splat('-')) else &@as([12 + term_fixtures.len * 13]u8, @splat('-'))});
for (std.enums.values(TermOp), 0..) |op, oi| {
o("{s:<12}", .{op.label()});
for (0..term_fixtures.len) |fi| {
@@ -1288,6 +1484,7 @@ fn writeJson(
const Base = struct {
med: [std.enums.values(Op).len][fixtures.len]u64,
+ min: [std.enums.values(Op).len][fixtures.len]u64 = @splat(@splat(0)),
term_med: [std.enums.values(TermOp).len][term_fixtures.len]u64,
};
@@ -1314,10 +1511,11 @@ fn parseBase(src: []const u8, opts: Options, bytes: *const [fixtures.len]usize)
defer parsed.deinit();
const report = parsed.value;
if (!std.mem.eql(u8, report.harness, harness_id)) return error.BaselineHarnessMismatch;
- inline for (std.meta.fields(BuildIdentity)) |field| {
- const before = @field(report.build, field.name);
- const after = @field(build_identity, field.name);
- const same = if (field.type == []const u8) std.mem.eql(u8, before, after) else before == after;
+ const info = @typeInfo(BuildIdentity).@"struct";
+ inline for (info.field_names, info.field_types) |name, T| {
+ const before = @field(report.build, name);
+ const after = @field(build_identity, name);
+ const same = if (T == []const u8) std.mem.eql(u8, before, after) else before == after;
if (!same) return error.BaselineBuildMismatch;
}
if (report.cols != opts.cols or report.rows != opts.rows or report.reps != opts.reps or
@@ -1353,6 +1551,7 @@ fn parseBase(src: []const u8, opts: Options, bytes: *const [fixtures.len]usize)
if (file_seen[oi][index]) return error.BaselineCoverage;
file_seen[oi][index] = true;
base.med[oi][index] = cell.med_us;
+ base.min[oi][index] = cell.min_us;
} else {
if (opts.only != null) return error.BaselineCoverage;
const ti = for (term_fixtures, 0..) |fixture, index| {
@@ -1397,8 +1596,22 @@ fn selfTest() !void {
&.{ "--terminal-mib", "1", "--only", "small" }, &.{ "--terminal-mib", "1", "--creation" },
&.{ "--terminal-mib", "1", "--base", "old.json" }, &.{ "--mini", "--creation" },
&.{ "--mini", "--terminal-mib", "1" }, &.{ "--mini", "--base", "old.json" },
- &.{ "--mini", "--only", "small" },
+ &.{ "--mini", "--only", "small" }, &.{ "--max-ratio", "3" },
}) |args| try testing.expectError(error.IncompatibleOptions, Options.parse(args));
+ try testing.expectError(error.InvalidMeasurement, Options.parse(&.{ "--base", "old.json", "--max-ratio", "0.5" }));
+ const gated = try Options.parse(&.{ "--only", "medium", "--base", "old.json", "--max-ratio", "3" });
+ try testing.expectEqual(@as(f64, 3), gated.max_ratio.?);
+ {
+ // A cell three and a half times its baseline's best fails; the
+ // rest pass.
+ var cells: [std.enums.values(Op).len][fixtures.len]Cell = @splat(@splat(.{}));
+ var base: Base = .{ .med = @splat(@splat(0)), .term_med = @splat(@splat(0)) };
+ base.min[1][1] = 100;
+ cells[1][1] = .{ .min_us = 290, .med_us = 300, .p90_us = 300, .max_us = 300 };
+ try gate(&cells, &base, 3);
+ cells[1][1].min_us = 350;
+ try testing.expectError(error.PerformanceRegression, gate(&cells, &base, 3));
+ }
const selected = try Options.parse(&.{ "--only", "small", "--reps", "2", "--cols", "80", "--rows", "24" });
try testing.expectEqual(@as(usize, 2), selected.reps);
try testing.expectEqual(@as(u16, 80), selected.cols);