diff options
Diffstat (limited to 'test/perf.zig')
| -rw-r--r-- | test/perf.zig | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/test/perf.zig b/test/perf.zig index f36d64ac..16066e9f 100644 --- a/test/perf.zig +++ b/test/perf.zig @@ -394,6 +394,8 @@ const Options = struct { mini: bool = false, /// The scans a frame's slice bounds, a call at a time (`measureSearch`). search: bool = false, + /// A picker's key and frame (`measurePick`). + pick: 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). @@ -410,7 +412,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, @"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, @"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, @@ -418,6 +420,7 @@ const Options = struct { .startup => opts.startup = true, .mini => opts.mini = true, .search => opts.search = true, + .pick => opts.pick = true, .@"self-test" => opts.self_test = true, else => { i += 1; @@ -480,6 +483,7 @@ pub fn main(init: std.process.Init) !void { 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); if (opts.search) return measureSearch(init.io); + if (opts.pick) return measurePick(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 @@ -1824,6 +1828,81 @@ fn measureSearch(io: std.Io) !void { } } +/// `--pick`: a picker's hot paths (core/Pick.zig, walk UI line D), each +/// a step and the frame that draws it, timed and its instructions counted +/// (user space, this thread): a key typed into a Find of 50,000 paths and +/// the frames after it while its names are scored; a cursor move over rows +/// that are files, and the frame after it that loads the preview into the +/// landing pane's body (a 2,000-line file read from the disk). +fn measurePick(io: std.Io) !void { + var random: [12]u8 = undefined; + io.random(&random); + const dir = try std.fmt.allocPrint(gpa, "/tmp/pardes-pick-{x}", .{random}); + defer gpa.free(dir); + try std.Io.Dir.createDirAbsolute(io, dir, .default_dir); + defer std.Io.Dir.cwd().deleteTree(io, dir) catch {}; + var counter: Instructions = try .open(); + defer counter.close(); + var body: std.ArrayList(u8) = .empty; + defer body.deinit(gpa); + for (0..2000) |i| try body.print(gpa, " const value_{d} = compute(value_{d}, \"a line of the preview\");\n", .{ i, i -| 1 }); + var name: [160]u8 = undefined; + for (0..20) |i| try writeFile(try std.fmt.bufPrint(&name, "{s}/pickme_{d}.zig", .{ dir, i }), body.items); + const start = try std.fmt.allocPrint(gpa, "{s}/start.zig", .{dir}); + defer gpa.free(start); + try writeFile(start, "const start = 1;\n"); + const core = try boot(); + defer core.deinit(); + core.settings.jumps = .walk; + pardes.look.lookAt(core, 0, start); + pump(core); + const id = filePane(core) orelse return error.OpenDidNotOpenFile; + pardes.Pick.open(core, id, .find, "", "", ""); + const pk = pardes.Pick.live(core) orelse return error.NoPicker; + // The listing as the disk engine would give it: 50,000 paths, the + // real files among them. + _ = core.stream.stop(); + pk.names.reset(); + const dirs = [_][]const u8{ "core", "dev/gui", "dev/tui", "runtime", "test/behaviour", "addons/pdf", "zig-pkg/ghostty/src/terminal" }; + const words = [_][]const u8{ "layout", "places", "names", "query", "stream", "surface", "replica", "tape", "kitty", "render" }; + for (0..50_000) |i| { + const path = if (i % 2500 == 0) try std.fmt.bufPrint(&name, "pickme_{d}.zig", .{i / 2500}) else try std.fmt.bufPrint(&name, "{s}/module_{d}/{s}_{d}.zig", .{ dirs[i % dirs.len], i / 64 % 997, words[i * 7 % words.len], i }); + try pk.names.add(gpa, path, 0, path.len, @TypeOf(pk.names).baseOf(path), 0); + } + pk.names.typed(gpa, ""); + while (pk.names.busy()) pk.names.rescore(gpa); + try frame(core); + const Step = struct { + fn run(c: *pardes.Pardes, ev: pardes.Event, n: *Instructions, s: *Slowest, hits: usize) !void { + const was = n.read(); + const t0 = nowNs(); + c.update(ev); + try frame(c); + s.add(nowNs() -| t0, n.read() -| was, hits); + } + }; + var keys: Slowest = .{}; + var after: Slowest = .{}; + for ("pickme") |ch| { + try Step.run(core, .{ .key = .{ .cp = ch, .text = &[_]u8{ch} } }, &counter, &keys, pk.names.hits.items.len); + while (pk.names.busy()) try Step.run(core, .tick, &counter, &after, pk.names.hits.items.len); + } + keys.report("pick key + frame", "pickme", pk.names.hits.items.len); + after.report("pick tick + frame while scoring", "pickme", pk.names.hits.items.len); + // The first preview, then the cursor moved and the preview after it. + try Step.run(core, .tick, &counter, &after, 0); + var moves: Slowest = .{}; + var previews: Slowest = .{}; + for (0..19) |_| { + try Step.run(core, .{ .key = .{ .cp = pardes.Key.down } }, &counter, &moves, 0); + try Step.run(core, .tick, &counter, &previews, 0); + } + moves.report("pick Down + frame", "pickme", pk.names.hits.items.len); + previews.report("pick preview tick + frame", "pickme", pk.names.hits.items.len); + const landing = core.panes[core.paneBySerial(pk.landing) orelse return error.NoLanding].?; + if (!std.mem.endsWith(u8, landing.file.?.path, ".zig") or std.mem.indexOf(u8, landing.file.?.path, "pickme_") == null) return error.NoPreview; +} + /// The longest of a scan's calls. const Slowest = struct { calls: usize = 0, |
