summaryrefslogtreecommitdiff
path: root/src/tracy.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-07-06 13:50:54 -0300
committerGabriel Schneider <[email protected]>2026-08-01 15:02:07 -0300
commita43dc216f03c0bfed51ca539d027a90adc689ac8 (patch)
treeeb9be20342c4af9773100f3fa0082a4ad30b2c26 /src/tracy.zig
parentde4def3548a6729b0dfd2120495a61beef8c8c2c (diff)
downloadpardes-a43dc216f03c0bfed51ca539d027a90adc689ac8.tar.gz
pardes-a43dc216f03c0bfed51ca539d027a90adc689ac8.zip
tty: coalesce queued input events into one frame; tracy zones behind -Dtracy
The tty shell rendered (core.render + full vaxis repaint + tree-sitter re-highlight of the visible window) after EVERY event, so a wheel flick over a highlighted file was 150 re-parses and 150 terminal repaints; the gui shell drains the SDL queue before drawing and never had the issue. Now the tty loop applies every queued input event, then renders once (batch cap 64; pty output keeps a frame per chunk so progress paints and transient-state waits behave exactly as before). Measured with tracy on a 2400-line .zig scroll script: 150 highlightFileRange calls at 1.85ms mean -> 4; render pipeline total 730ms -> 64ms; 364 frames -> 39. Snap suite 18/18. Tracy: -Dtracy=<path-to-tracy-checkout> compiles TracyClient.cpp into the binary and turns src/tracy.zig zones live (default off, all no-ops). Sampling, callstacks, system tracing and the crash handler are disabled: tracy's symbol worker SIGSEGVs on this binary's debug info and its crash handler then parks every thread before the first frame. Capture: tracy-capture -o t.tracy; export: tracy-csvexport t.tracy.
Diffstat (limited to 'src/tracy.zig')
-rw-r--r--src/tracy.zig50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/tracy.zig b/src/tracy.zig
new file mode 100644
index 00000000..3b0b8621
--- /dev/null
+++ b/src/tracy.zig
@@ -0,0 +1,50 @@
+//! Minimal Tracy client (the Zig compiler's pattern): `zone(@src(), "name")`
+//! ... `.end()`, plus `frameMark()`. Everything compiles to a no-op unless the
+//! build sets -Dtracy=<path-to-tracy-checkout>, which also compiles and links
+//! TracyClient.cpp. Capture with tracy-capture, inspect with tracy-csvexport.
+const std = @import("std");
+const builtin = @import("builtin");
+
+pub const enable = if (builtin.is_test) false else @import("pardes_config").enable_tracy;
+
+const SourceLocation = extern struct {
+ name: ?[*:0]const u8,
+ function: [*:0]const u8,
+ file: [*:0]const u8,
+ line: u32,
+ color: u32,
+};
+
+pub const Ctx = if (enable) extern struct {
+ id: u32,
+ active: i32,
+
+ pub inline fn end(c: @This()) void {
+ ___tracy_emit_zone_end(c);
+ }
+} else struct {
+ pub inline fn end(_: @This()) void {}
+};
+
+pub inline fn zone(comptime src: std.builtin.SourceLocation, comptime name: [:0]const u8) Ctx {
+ if (!enable) return .{};
+ const static = struct {
+ const loc: SourceLocation = .{
+ .name = name.ptr,
+ .function = src.fn_name.ptr,
+ .file = src.file.ptr,
+ .line = src.line,
+ .color = 0,
+ };
+ };
+ return ___tracy_emit_zone_begin(&static.loc, 1);
+}
+
+pub inline fn frameMark() void {
+ if (!enable) return;
+ ___tracy_emit_frame_mark(null);
+}
+
+extern fn ___tracy_emit_zone_begin(srcloc: *const SourceLocation, active: c_int) Ctx;
+extern fn ___tracy_emit_zone_end(ctx: Ctx) void;
+extern fn ___tracy_emit_frame_mark(name: ?[*:0]const u8) void;