summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 21:37:08 -0300
committerGabriel Schneider <[email protected]>2026-11-06 21:37:08 -0300
commit09b992cedf314727f7391f3497cd7a82cb7955db (patch)
treec1ccc603741602bc18c19ae6fbc6c79b7cb0b944
parent20d79644b6283a425ad0daed869afed8e706b8c2 (diff)
downloadpardes-09b992cedf314727f7391f3497cd7a82cb7955db.tar.gz
pardes-09b992cedf314727f7391f3497cd7a82cb7955db.zip
kinds #45, the PDF benches drive pdf.zig, take another build's library (--addon, so pdf.c's from the base runs beside it under one core) and a touchpad's turns (--turn F: whole notches glide in pdf.zig, so the like-for-like fling is turns), and the scroll bench's first frame is as a host shows it, the frame after the first page lands (settled_ns, the page ahead landed too, the number it printed before)
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--test/pdf_pointer_bench.zig7
-rw-r--r--test/pdf_scroll_bench.zig45
2 files changed, 36 insertions, 16 deletions
diff --git a/test/pdf_pointer_bench.zig b/test/pdf_pointer_bench.zig
index 7a39dd88..521d451a 100644
--- a/test/pdf_pointer_bench.zig
+++ b/test/pdf_pointer_bench.zig
@@ -1,7 +1,7 @@
//! Pointer gestures over a pane of the pdf addon: hovering words (the Look
//! preview highlight), and dragging a selection to its release.
//!
-//! zig build pdf-pointer-bench -Doptimize=ReleaseFast -- [--label L] [--reps N] [--path FILE]
+//! zig build pdf-pointer-bench -Doptimize=ReleaseFast -- [--label L] [--reps N] [--path FILE] [--addon LIB]
//! [--cell WxH] [--scroll NOTCHES]
//!
//! Every frame is timed the way a shell pump spends it: the event through
@@ -30,6 +30,7 @@ const rows: u16 = 40;
const Config = struct {
path: []const u8 = "docs/design.pdf",
+ addon: []const u8 = bench_config.pdf_addon,
label: []const u8 = "run",
reps: usize = 5,
/// Wheel notches before the gestures, off the sparse title page.
@@ -45,7 +46,7 @@ pub fn main(init: std.process.Init) !void {
var i: usize = 1;
while (i + 1 < args.len) : (i += 2) {
const value = args[i + 1];
- if (std.mem.eql(u8, args[i], "--path")) config.path = value else if (std.mem.eql(u8, args[i], "--label")) config.label = value else if (std.mem.eql(u8, args[i], "--reps")) config.reps = try std.fmt.parseUnsigned(usize, value, 10) else if (std.mem.eql(u8, args[i], "--scroll")) config.scroll = try std.fmt.parseUnsigned(usize, value, 10) else if (std.mem.eql(u8, args[i], "--cell")) {
+ if (std.mem.eql(u8, args[i], "--path")) config.path = value else if (std.mem.eql(u8, args[i], "--addon")) config.addon = value else if (std.mem.eql(u8, args[i], "--label")) config.label = value else if (std.mem.eql(u8, args[i], "--reps")) config.reps = try std.fmt.parseUnsigned(usize, value, 10) else if (std.mem.eql(u8, args[i], "--scroll")) config.scroll = try std.fmt.parseUnsigned(usize, value, 10) else if (std.mem.eql(u8, args[i], "--cell")) {
var it = std.mem.splitScalar(u8, value, 'x');
config.cell_w = try std.fmt.parseUnsigned(u16, it.next() orelse "", 10);
config.cell_h = try std.fmt.parseUnsigned(u16, it.next() orelse "", 10);
@@ -162,7 +163,7 @@ fn measure(config: Config, round: usize) !u64 {
const cell: pardes.CellPixels = .{ .w = config.cell_w, .h = config.cell_h };
core.advance(run.now);
core.update(.{ .resize = .{ .cols = cols, .rows = rows, .cell_pixels = cell } });
- pardes.Addon.perform(core, .load, 0, bench_config.pdf_addon);
+ pardes.Addon.perform(core, .load, 0, config.addon);
drain(core);
const real = try std.Io.Dir.cwd().realPathFileAlloc(std.Io.Threaded.global_single_threaded.io(), config.path, gpa);
defer gpa.free(real);
diff --git a/test/pdf_scroll_bench.zig b/test/pdf_scroll_bench.zig
index 58e7cfb0..bb4640f7 100644
--- a/test/pdf_scroll_bench.zig
+++ b/test/pdf_scroll_bench.zig
@@ -1,11 +1,13 @@
//! Scoreboard for FAST scrolling of a PDF's continuous strip: a pane of the
-//! pdf addon (addons/pdf/pdf.c), driven through the core as a shell drives
+//! pdf addon (addons/pdf/pdf.zig), driven through the core as a shell drives
//! it.
//!
//! zig build pdf-scroll-bench -Doptimize=ReleaseFast the numbers
//! zig build pdf-scroll-bench -Doptimize=ReleaseFast -- --json
//! zig build pdf-scroll-bench -Doptimize=ReleaseFast -- --warmup 1 --reps 15
//! zig build pdf-scroll-bench -Doptimize=ReleaseFast -- --path other.pdf
+//! zig build pdf-scroll-bench -Doptimize=ReleaseFast -- --addon other/pdf.so another build's
+//! zig build pdf-scroll-bench -Doptimize=ReleaseFast -- --turn 0.999 a touchpad's turns, not notches
//! zig build pdf-scroll-bench -Doptimize=ReleaseFast -- --cell 16x32 a 2x display
//!
//! A shell pump drains every input the OS queued since the last present and
@@ -45,6 +47,10 @@ const max_frames: usize = 2048;
const Config = struct {
path: []const u8 = "docs/design.pdf",
+ addon: []const u8 = bench_config.pdf_addon,
+ /// Each wheel event's turn: 0, a whole notch (a terminal's; a kind may
+ /// glide it), else a touchpad's fraction, moved at once.
+ turn: f32 = 0,
json: bool = false,
warmup: usize = 2,
reps: usize = 25,
@@ -111,10 +117,12 @@ fn parseArgs(args: []const []const u8) Config {
config.json = true;
continue;
}
- if (i + 1 >= args.len) fatal("usage: pardes-pdf-scroll-bench [--json] [--warmup N] [--reps N] [--path FILE] [--frames N] [--slow-frames N] [--cell WxH]", .{});
+ if (i + 1 >= args.len) fatal("usage: pardes-pdf-scroll-bench [--json] [--warmup N] [--reps N] [--path FILE] [--addon LIB] [--turn F] [--frames N] [--slow-frames N] [--cell WxH]", .{});
i += 1;
const v = args[i];
- if (std.mem.eql(u8, a, "--warmup")) config.warmup = parseCount(a, v) else if (std.mem.eql(u8, a, "--reps")) config.reps = parseCount(a, v) else if (std.mem.eql(u8, a, "--path")) config.path = v else if (std.mem.eql(u8, a, "--frames")) config.frames = parseCount(a, v) else if (std.mem.eql(u8, a, "--slow-frames")) config.slow_frames = parseCount(a, v) else if (std.mem.eql(u8, a, "--cell")) {
+ if (std.mem.eql(u8, a, "--warmup")) config.warmup = parseCount(a, v) else if (std.mem.eql(u8, a, "--reps")) config.reps = parseCount(a, v) else if (std.mem.eql(u8, a, "--path")) config.path = v else if (std.mem.eql(u8, a, "--addon")) config.addon = v else if (std.mem.eql(u8, a, "--turn")) {
+ config.turn = std.fmt.parseFloat(f32, v) catch fatal("--turn {s}: not a number", .{v});
+ } else if (std.mem.eql(u8, a, "--frames")) config.frames = parseCount(a, v) else if (std.mem.eql(u8, a, "--slow-frames")) config.slow_frames = parseCount(a, v) else if (std.mem.eql(u8, a, "--cell")) {
var it = std.mem.splitScalar(u8, v, 'x');
config.cell = .{ .w = @intCast(parseCount(a, it.next() orelse "")), .h = @intCast(parseCount(a, it.next() orelse "")) };
} else fatal("unknown flag {s}", .{a});
@@ -178,8 +186,11 @@ fn settle(core: *pardes.Pardes) void {
while (running.items.len > 0) drain(core);
}
-const Travel = struct { max_scroll: f64, pages: u32, first_frame_ns: u64 };
+const Travel = struct { max_scroll: f64, pages: u32, first_frame_ns: u64, settled_ns: u64 };
+/// When bootCore's Look began, and when its first frame showed a page's
+/// pixels (the first frame); `settled` is its end, the page ahead landed too.
+var first_page: u64 = 0;
/// When bootCore's Look began: the first frame is from there to the first
/// page landed (the document opened, sized and drawn).
var look_started: u64 = 0;
@@ -191,7 +202,7 @@ fn bootCore(config: Config) !*pardes.Pardes {
errdefer core.deinit();
core.view().frontend.native_images = true;
core.update(.{ .resize = .{ .cols = bench_cols, .rows = bench_rows, .cell_pixels = config.cell } });
- pardes.Addon.perform(core, .load, 0, bench_config.pdf_addon);
+ pardes.Addon.perform(core, .load, 0, config.addon);
drain(core);
var line: [4200]u8 = undefined;
const real = try std.Io.Dir.cwd().realPathFileAlloc(std.Io.Threaded.global_single_threaded.io(), config.path, gpa);
@@ -205,11 +216,19 @@ fn bootCore(config: Config) !*pardes.Pardes {
drain(core);
var arena = std.heap.ArenaAllocator.init(gpa);
defer arena.deinit();
+ first_page = 0;
for (0..4) |_| {
- _ = arena.reset(.retain_capacity);
- _ = try core.render(arena.allocator());
core.update(.tick);
- drain(core);
+ // A frame as each job lands (a host's), until the first page is shown.
+ while (true) {
+ drain(core);
+ _ = arena.reset(.retain_capacity);
+ const shown = try core.render(arena.allocator());
+ for (shown.placements.items) |pl| if (pl.raster.w > 1 and first_page == 0) {
+ first_page = nowNs() -| look_started;
+ };
+ if (first_page != 0 or running.items.len == 0) break;
+ }
settle(core);
}
if ((core.panes[pdf] orelse return error.NoPane).addon == null) return error.NotAPdf;
@@ -224,7 +243,7 @@ fn probeTravel(config: Config) Travel {
const core = bootCore(config) catch |err| fatal("cannot open {s} as a PDF pane: {t}", .{ config.path, err });
defer core.deinit();
defer settle(core);
- const first_frame_ns = nowNs() -| look_started;
+ const settled_ns = nowNs() -| look_started;
const slot = pdfPane(core).addon.?;
if (slot.thumb_span <= 0) fatal("{s}: the strip never laid out", .{config.path});
// The strip is the window over the share of it shown.
@@ -232,7 +251,7 @@ fn probeTravel(config: Config) Travel {
var pages: u32 = 0;
const prefix = slot.prefix.slice();
if (std.mem.indexOfScalar(u8, prefix, '/')) |slash| pages = std.fmt.parseInt(u32, prefix[slash + 1 .. prefix.len - 1], 10) catch 0;
- return .{ .max_scroll = window_px / slot.thumb_span - window_px, .pages = pages, .first_frame_ns = first_frame_ns };
+ return .{ .max_scroll = window_px / slot.thumb_span - window_px, .pages = pages, .first_frame_ns = first_page, .settled_ns = settled_ns };
}
fn measure(config: Config, plan: Plan) !Result {
@@ -261,7 +280,7 @@ fn measure(config: Config, plan: Plan) !Result {
for (0..plan.frames) |frame| {
const button: pardes.Mouse.Button = if (plan.scenario == .fling_reverse and frame >= plan.down_frames) .wheel_up else .wheel_down;
const started = nowNs();
- for (0..ticks) |_| core.update(.{ .mouse = .{ .button = button, .kind = .press, .col = rect.x + rect.w / 2, .row = rect.y + rect.h / 2 } });
+ for (0..ticks) |_| core.update(.{ .mouse = .{ .button = button, .kind = .press, .col = rect.x + rect.w / 2, .row = rect.y + rect.h / 2, .amount = config.turn } });
_ = arena.reset(.retain_capacity);
const surface = try core.render(arena.allocator());
drain(core);
@@ -312,7 +331,7 @@ fn measure(config: Config, plan: Plan) !Result {
fn reportText(config: Config, travel: Travel, results: []const Result) void {
std.debug.print("pardes PDF fast-scroll benchmark ({s}): {s}, {d} pages, {d:.0}px of travel, cells {d}x{d}px\n", .{ bench_config.core_optimize, config.path, travel.pages, travel.max_scroll, config.cell.w, config.cell.h });
- std.debug.print("first frame of a fresh pane: {d}us; every number is ONE FRAME (notches + render + drain)\n", .{travel.first_frame_ns / 1000});
+ std.debug.print("first frame of a fresh pane (its first page shown): {d}us, the page ahead landed too: {d}us; every number is ONE FRAME (notches + render + drain)\n", .{ travel.first_frame_ns / 1000, travel.settled_ns / 1000 });
std.debug.print("{s:<14} {s:>6} {s:>7} {s:>10} {s:>10} {s:>10} {s:>10} {s:>10} {s:>8} {s}\n", .{ "scenario", "frames", "notches", "min", "median", "p90", "p99", "max", "rasters", "visual" });
for (results) |r| std.debug.print("{s:<14} {d:>6} {d:>7} {d:>10} {d:>10} {d:>10} {d:>10} {d:>10} {d:>8} {x:0>16}\n", .{ r.name, r.frames, r.ticks_per_frame, r.min_ns, r.median_ns, r.p90_ns, r.p99_ns, r.max_ns, r.rasterizations, r.visual });
}
@@ -320,7 +339,7 @@ fn reportText(config: Config, travel: Travel, results: []const Result) void {
fn reportJson(io: std.Io, config: Config, travel: Travel, results: []const Result) void {
var storage: [16 * 1024]u8 = undefined;
var out: std.Io.Writer = .fixed(&storage);
- out.print("{{\"benchmark\":\"pardes-pdf-scroll\",\"build\":\"{s}\",\"path\":\"{s}\",\"pages\":{d},\"strip_px\":{d:.0},\"first_frame_ns\":{d},\"warmup\":{d},\"reps\":{d},\"results\":[", .{ bench_config.core_optimize, config.path, travel.pages, travel.max_scroll, travel.first_frame_ns, config.warmup, config.reps }) catch return;
+ out.print("{{\"benchmark\":\"pardes-pdf-scroll\",\"build\":\"{s}\",\"path\":\"{s}\",\"pages\":{d},\"strip_px\":{d:.0},\"first_frame_ns\":{d},\"settled_ns\":{d},\"warmup\":{d},\"reps\":{d},\"results\":[", .{ bench_config.core_optimize, config.path, travel.pages, travel.max_scroll, travel.first_frame_ns, travel.settled_ns, config.warmup, config.reps }) catch return;
for (results, 0..) |r, i| out.print("{s}{{\"scenario\":\"{s}\",\"frames\":{d},\"notches_per_frame\":{d},\"min_ns\":{d},\"median_ns\":{d},\"p90_ns\":{d},\"p99_ns\":{d},\"max_ns\":{d},\"total_ns\":{d},\"rasterizations\":{d},\"images\":{d},\"visual\":\"{x:0>16}\"}}", .{ if (i == 0) "" else ",", r.name, r.frames, r.ticks_per_frame, r.min_ns, r.median_ns, r.p90_ns, r.p99_ns, r.max_ns, r.total_ns, r.rasterizations, r.images, r.visual }) catch return;
out.writeAll("]}\n") catch return;
std.Io.File.stdout().writeStreamingAll(io, out.buffered()) catch {};