From 5f1f95098611b077bd7e0ca27283fa0e02d1adbc Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 11:46:18 -0300 Subject: recorder: a moment is its events, state is at keyframes Folding every event into persistent state at every moment cost 750 bytes a step and 2 KB a scattered 8-byte write: the tree's path copied each time. Now a moment stores its events alone, in a compact code (a flags byte, varints, time as a difference, registers as the ones that changed), and the state (threads, memory, heap, variables, mappings, strings) is written at a keyframe a batch, sharing with the one before. A reader replays at most a batch over a keyframe, and keeps four positions replayed, so playing forward reads one moment a step. Of a memory write the recorder keeps the spans that differ from what it holds, so a region read again costs what changed in it. It stops at max_bytes (1 GiB). A step with registers: 749 bytes to 57. fib(12) by instruction, 142 000 moments: 111 MB to 8 MB, 197 000 moments/s. bench-store measures the rest. --- build.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'build.zig') diff --git a/build.zig b/build.zig index cbcd493..c740c5b 100644 --- a/build.zig +++ b/build.zig @@ -75,6 +75,19 @@ pub fn build(b: *std.Build) void { emit.expectStdErrMatch("exit 7"); core.dependOn(&emit.step); + const bench = b.addExecutable(.{ .name = "bench-store", .root_module = b.createModule(.{ + .root_source_file = b.path("bench/store.zig"), + .target = target, + .optimize = .ReleaseFast, + .imports = &.{.{ .name = "ztrace", .module = b.createModule(.{ + .root_source_file = b.path("src/trace/root.zig"), + .target = target, + .optimize = .ReleaseFast, + .imports = &.{.{ .name = "xitdb", .module = xitdb }}, + }) }}, + }) }); + b.step("bench-store", "What a recording costs a moment").dependOn(&b.addRunArtifact(bench).step); + // Each area adds its own artifacts, targets and test step. @import("build/debugger.zig").add(ctx); @import("build/agent.zig").add(ctx); -- cgit v1.3