diff options
Diffstat (limited to 'test/perf.zig')
| -rw-r--r-- | test/perf.zig | 214 |
1 files changed, 209 insertions, 5 deletions
diff --git a/test/perf.zig b/test/perf.zig index 16066e9f..8e622680 100644 --- a/test/perf.zig +++ b/test/perf.zig @@ -70,6 +70,31 @@ const Op = enum { /// the window: a kind's frame costs its window's cells, never its /// picture (docs: architecture ยง16.1, its trigger 5% of a frame). image_frame, + /// The walk UI's tag states (TagState.zig), each key pumped and the + /// frame that draws it: SPC struck at rest, its level shown when its + /// delay is up, Esc back to rest (three frames, two keys). + spc, + /// A Down in SPC's unrolled level: its cursor a row on, the band drawn. + spc_down, + /// A character typed in Help's field and a Backspace: its rows + /// filtered again each time (two keys). + help_type, + /// describe-key's `g d` replayed: the level and the leaf's doc under the + /// tag (two keys). + describe, + /// `j` and `k` at rest in the same loop (two keys, two frames): what + /// the tag states' keys compare with (key-down's frames each draw + /// another place of the file). + rest_keys, + + /// Run only when named (`--op`): a full run, its cells and the sums a + /// gate takes over them (perfops' "terminal on all") are as before. + fn named(o: Op) bool { + return switch (o) { + .spc, .spc_down, .help_type, .describe, .rest_keys => true, + else => false, + }; + } fn label(o: Op) []const u8 { return switch (o) { @@ -88,6 +113,11 @@ const Op = enum { .body_appends => "body-appends", .deep_selection => "deep-sel", .image_frame => "image-frame", + .spc => "spc", + .spc_down => "spc-down", + .help_type => "help-type", + .describe => "describe", + .rest_keys => "rest-keys", }; } }; @@ -396,6 +426,8 @@ const Options = struct { search: bool = false, /// A picker's key and frame (`measurePick`). pick: bool = false, + /// The walk UI's line F: registers, painted targets, themes (`measureWalkF`). + walkf: bool = false, terminal_mib: ?usize = null, /// The real binary's keystroke-to-present, `yes` stream and big open /// (a tty pardes), or its keystrokes alone (a pardes-gui). @@ -412,7 +444,7 @@ 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, startup, mini, search, pick, @"terminal-mib", @"self-test", reps, cols, rows, base, only, op, @"max-ratio", live, @"live-gui" }, arg[2..]) orelse + const option = std.meta.stringToEnum(enum { json, creation, startup, mini, search, pick, walkf, @"terminal-mib", @"self-test", reps, cols, rows, base, only, op, @"max-ratio", live, @"live-gui" }, arg[2..]) orelse return error.UnknownOption; switch (option) { .json => opts.json = true, @@ -421,6 +453,7 @@ const Options = struct { .mini => opts.mini = true, .search => opts.search = true, .pick => opts.pick = true, + .walkf => opts.walkf = true, .@"self-test" => opts.self_test = true, else => { i += 1; @@ -484,6 +517,7 @@ pub fn main(init: std.process.Init) !void { if (opts.mini) return measureMini(init.io, init.gpa, reps, opts.json); if (opts.search) return measureSearch(init.io); if (opts.pick) return measurePick(init.io); + if (opts.walkf) return measureWalkF(init.io); if (opts.live) |exe| return measureLive(init.io, exe, false, reps, opts.json); if (opts.live_gui) |exe| return measureLive(init.io, exe, true, reps, opts.json); // The image-frame cells load the image addon by the path the build baked @@ -528,6 +562,7 @@ pub fn main(init: std.process.Init) !void { for (fixtures, 0..) |fx, fi| { if (only) |name| if (!std.mem.eql(u8, name, fx.name)) continue; if (opts.op) |o| if (o != op) continue; + if (op.named() and opts.op == null) continue; cells[oi][fi] = try measure(op, fx, paths[fi], bytes[fi], reps); } } @@ -542,7 +577,7 @@ pub fn main(init: std.process.Init) !void { } } - if (opts.json) try reportJson(init.io, &cells, &term_cells, &bytes, opts) else 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.op, opts.base, base); if (opts.max_ratio) |ratio| try gate(&cells, &base.?, ratio); } @@ -587,6 +622,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u 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), + .spc, .spc_down, .help_type, .describe, .rest_keys => return measureTag(op, path, reps), else => {}, } if (op == .open) { @@ -641,7 +677,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, .client_key_down, .client_edit_char, .client_delete_undo => unreachable, + .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo, .spc, .spc_down, .help_type, .describe, .rest_keys => unreachable, .render, .deep_selection => {}, .key_down => core.update(.{ .key = .{ .cp = 'j', .text = "j" } }), .key_right => core.update(.{ .key = .{ .cp = 'l', .text = "l" } }), @@ -655,7 +691,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, .client_key_down, .client_edit_char, .client_delete_undo => unreachable, + .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo, .spc, .spc_down, .help_type, .describe, .rest_keys => 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) @@ -740,6 +776,68 @@ fn clientKey(a: *pardes.replica.Authority, r: *pardes.replica.Replica, ev: parde r.settle(); } +/// A tag state's keys on the fixture's pane, each pumped and its frame +/// drawn, from the state the op starts in (entered untimed); the state +/// checked after each repetition. +fn measureTag(op: Op, path: []const u8, reps: usize) !Cell { + const Key = pardes.Key; + const warmup = 3; + const samples = try gpa.alloc(u64, reps); + defer gpa.free(samples); + const core = try boot(); + defer core.deinit(); + pardes.look.lookAt(core, 0, path); + pump(core); + const id = filePane(core) orelse return error.OpenDidNotOpenFile; + core.view().active = id; + const enter: []const Key = switch (op) { + .spc, .rest_keys => &.{}, + .spc_down => &.{ .{ .cp = ' ', .text = " " }, .{ .cp = Key.down } }, + .help_type => &.{ .{ .cp = ' ', .text = " " }, .{ .cp = '?', .text = "?" } }, + .describe => &.{ .{ .cp = ' ', .text = " " }, .{ .cp = 'h', .text = "h" }, .{ .cp = 'k', .text = "k" } }, + else => unreachable, + }; + for (enter) |k| core.update(.{ .key = k }); + pump(core); + _ = try frame(core); + const keys: []const Key = switch (op) { + .spc => &.{ .{ .cp = ' ', .text = " " }, .{ .cp = Key.escape } }, + .spc_down => &.{.{ .cp = Key.down }}, + .help_type => &.{ .{ .cp = 'e', .text = "e" }, .{ .cp = Key.backspace } }, + .describe => &.{ .{ .cp = 'g', .text = "g" }, .{ .cp = 'd', .text = "d" } }, + .rest_keys => &.{ .{ .cp = 'j', .text = "j" }, .{ .cp = 'k', .text = "k" } }, + else => unreachable, + }; + const s = &core.view().tag_state; + for (0..warmup + samples.len) |n| { + const t0 = nowNs(); + for (keys) |k| { + core.update(.{ .key = k }); + pump(core); + _ = try frame(core); + // SPC's level when its delay is up: the frame that shows it. + if (op == .spc and k.cp == ' ') { + core.advance(core.clock.now_ns); + core.clock.now_ns = s.due_ns; + if (!pardes.TagState.shown(core, core.view())) return error.LevelNotShown; + _ = try frame(core); + } + } + const dt = nowNs() -| t0; + const held = switch (op) { + .spc => s.kind == .rest and s.root == null, + .spc_down => s.unrolled and core.panes[id].?.band_rows > 0, + .help_type => s.kind == .help and s.field.len == 0 and s.nhits > 0, + .describe => s.kind == .describe and s.found, + .rest_keys => s.kind == .rest and s.root == null and core.panes[id].?.body.cur_row == 0, + else => unreachable, + }; + if (!held) return error.TagStateLost; + if (n >= warmup) samples[n - warmup] = dt / 1000; + } + return summarize(samples); +} + 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); @@ -1826,6 +1924,38 @@ fn measureSearch(io: std.Io) !void { } slow.report("fill", pattern, set.hits.items.len); } + + // A key typed into a text prompt in the tag (core/Prompt.zig) on a 1 MB + // file, with its frame: `/` from the middle (its places from the view on, + // a frame's budget a tick after), `s` over the whole text (`%`). + const mb: Fixture = .{ .name = "onemeg", .lines = 17_000, .cols = 60 }; + const mb_path = try std.fmt.allocPrint(gpa, "{s}/{s}.zig", .{ dir, mb.name }); + defer gpa.free(mb_path); + const mb_text = try generate(mb); + try writeFile(mb_path, mb_text); + std.debug.print("prompt keys over {d} bytes\n", .{mb_text.len}); + gpa.free(mb_text); + for ([_][]const u8{ "/", "%s" }) |opener| for ([_][]const u8{ "helper", "qqq" }) |typed| { + const core = try boot(); + defer core.deinit(); + pardes.look.lookAt(core, 0, mb_path); + pump(core); + const id = filePane(core) orelse return error.OpenDidNotOpenFile; + const pane = core.panes[id].?; + seek(pane, mb, 0); + pane.file.?.scroll = mb.lines / 2; + pane.body.cur_row = @intCast(mb.lines / 2); + _ = try frame(core); + for (opener) |c| core.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + _ = try frame(core); + for (typed, 0..) |c, n| { + const was = counter.read(); + const t0 = nowNs(); + core.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + _ = try frame(core); + std.debug.print("prompt {s} \"{s}\": {d} instructions, {d} us (key and frame)\n", .{ opener, typed[0 .. n + 1], counter.read() -| was, (nowNs() -| t0) / 1000 }); + } + }; } /// `--pick`: a picker's hot paths (core/Pick.zig, walk UI line D), each @@ -1903,6 +2033,77 @@ fn measurePick(io: std.Io) !void { if (!std.mem.endsWith(u8, landing.file.?.path, ".zig") or std.mem.indexOf(u8, landing.file.?.path, "pickme_") == null) return error.NoPreview; } +/// `--walkf`: line F's hot paths in a 2,000-line file, each a step and +/// the frame that draws it, its instructions counted: a key in the +/// registers' level unrolled (Down, its value step read again); a frame +/// with `]`'s targets painted against one at rest; a cursor move in the +/// themes picker (the window wearing the next theme). +fn measureWalkF(io: std.Io) !void { + var random: [12]u8 = undefined; + io.random(&random); + const dir = try std.fmt.allocPrint(gpa, "/tmp/pardes-walkf-{x}", .{random}); + defer gpa.free(dir); + try std.Io.Dir.createDirAbsolute(io, dir, .default_dir); + defer std.Io.Dir.cwd().deleteTree(io, dir) catch {}; + const path = try std.fmt.allocPrint(gpa, "{s}/walkf.zig", .{dir}); + defer gpa.free(path); + var body: std.ArrayList(u8) = .empty; + defer body.deinit(gpa); + for (0..250) |i| try body.print(gpa, "/// The {d}th.\nfn f{d}(a: u32) u32 {{\n const b = a + {d};\n return b;\n}}\n\ntest \"f{d}\" {{\n}}\n", .{ i, i, i, i }); + try writeFile(path, body.items); + var counter: Instructions = try .open(); + defer counter.close(); + const core = try boot(); + defer core.deinit(); + core.settings.jumps = .walk; + pardes.look.lookAt(core, 0, path); + pump(core); + _ = filePane(core) orelse return error.OpenDidNotOpenFile; + for ("abcdefgh", 0..) |r, i| try core.registers.put(gpa, r, body.items[i * 40 ..][0..200], 0, 1, true); + try frame(core); + const Step = struct { + fn run(c: *pardes.Pardes, ev: pardes.Event, n: *Instructions, s: *Slowest) !void { + const was = n.read(); + const t0 = nowNs(); + c.update(ev); + try frame(c); + s.add(nowNs() -| t0, n.read() -| was, 0); + } + }; + const shown = struct { + fn wait(c: *pardes.Pardes) !void { + c.advance(c.clock.now_ns); + c.clock.now_ns = c.view().tag_state.due_ns; + try frame(c); + } + }; + // Registers: `"`, its level shown, unrolled; then Down over its rows. + core.update(.{ .key = .{ .cp = '"' } }); + try shown.wait(core); + core.update(.{ .key = .{ .cp = pardes.Key.down } }); + var regs: Slowest = .{}; + for (0..8) |_| try Step.run(core, .{ .key = .{ .cp = pardes.Key.down } }, &counter, ®s); + regs.report("registers Down + frame", "\"", 0); + core.update(.{ .key = .{ .cp = pardes.Key.escape } }); + // A frame at rest, then frames with `]`'s targets painted. + var rest: Slowest = .{}; + var painted: Slowest = .{}; + for (0..8) |_| try Step.run(core, .tick, &counter, &rest); + core.update(.{ .key = .{ .cp = ']' } }); + try shown.wait(core); + for (0..8) |_| try Step.run(core, .tick, &counter, &painted); + rest.report("tick + frame at rest", "", 0); + painted.report("tick + frame, ] painted", "]", 0); + core.update(.{ .key = .{ .cp = pardes.Key.escape } }); + // The themes picker: Down, the window wearing the next. + pardes.Pick.open(core, core.view().active, .themes, "", "", ""); + try frame(core); + var themes: Slowest = .{}; + for (0..8) |_| try Step.run(core, .{ .key = .{ .cp = pardes.Key.down } }, &counter, &themes); + themes.report("themes Down + frame", "", 0); + if (core.theme_preview == null) return error.NoThemePreview; +} + /// The longest of a scan's calls. const Slowest = struct { calls: usize = 0, @@ -2067,6 +2268,7 @@ fn reportText( term_cells: *const [std.enums.values(TermOp).len][term_fixtures.len]Cell, bytes: *const [fixtures.len]usize, reps: usize, + named: ?Op, base_path: ?[]const u8, base: ?Base, ) void { @@ -2090,6 +2292,7 @@ fn reportText( 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| { + if (op.named() and named != op) continue; o("{s:<12}", .{op.label()}); for (0..fixtures.len) |fi| { const c = cells[oi][fi]; @@ -2179,6 +2382,7 @@ fn writeJson( for (fixtures, 0..) |fx, fi| { if (opts.only) |name| if (!std.mem.eql(u8, name, fx.name)) continue; if (opts.op) |o| if (o != op) continue; + if (op.named() and opts.op == null) continue; const c = cells[oi][fi]; try out.print("{s}{{\"op\":\"{s}\",\"fixture\":\"{s}\",\"min_us\":{d},\"med_us\":{d},\"p90_us\":{d},\"max_us\":{d}}}", .{ if (first) "" else ",", op.label(), fx.name, c.min_us, c.med_us, c.p90_us, c.max_us, @@ -2283,7 +2487,7 @@ fn parseBase(src: []const u8, opts: Options, bytes: *const [fixtures.len]usize) } for (fixtures, 0..) |fixture, fi| { if (opts.only) |name| if (!std.mem.eql(u8, name, fixture.name)) continue; - for (file_seen) |row| if (!row[fi]) return error.BaselineCoverage; + for (file_seen, std.enums.values(Op)) |row, op| if (!row[fi] and !op.named()) return error.BaselineCoverage; } if (opts.only == null) for (term_seen) |row| { for (row) |seen| if (!seen) return error.BaselineCoverage; |
