diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 12:30:52 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 12:37:33 -0300 |
| commit | c0f5bd34d0f5339626d2c28c4012db7be46b55f3 (patch) | |
| tree | 391ae454deae06617dd388cafc6ae525a5b3007b | |
| parent | 8ac0639bfc0186acedb11759432a2cfa277193f2 (diff) | |
| download | computeranim-c0f5bd34d0f5339626d2c28c4012db7be46b55f3.tar.gz computeranim-c0f5bd34d0f5339626d2c28c4012db7be46b55f3.zip | |
recorder: a keyframe every 4096 moments, measured on Lua
Lua 5.4 through ztrace cc with everything instrumented, on a ten-line
script: 3.2 million moments, and at a keyframe every 256 the keyframes
were half of its 304 MB. At 4096 it is 156 MB and records in 1.7 s
instead of 3.9; a seek to any moment is a millisecond on average, three at
worst, and reading in order 6 µs a moment. The README has the table.
| -rw-r--r-- | README.md | 31 | ||||
| -rw-r--r-- | src/trace/store.zig | 10 |
2 files changed, 28 insertions, 13 deletions
@@ -50,7 +50,7 @@ is another, with the recorder at its far end. An xitdb file, kept small. A **moment** stores only its events, encoded compactly (registers as the ones that changed since the thread's last). The -program's **state** is stored at a keyframe every 256 moments, each sharing +program's **state** is stored at a keyframe every 4096 moments, each sharing what did not change with the one before; the state at any moment is the keyframe before it with the moments since replayed over it. `Trace.moment(i)` is any of them, in any order: time travel is an index. @@ -78,19 +78,32 @@ What a moment costs (`zig build bench-store`; release, this machine): | each moment | bytes | ns | | --- | --- | --- | -| a mark | 29 | 560 | -| a step with registers | 57 | 1100 | -| ... and a word pushed on the stack | 75 | 960 | -| a word written somewhere in 1 MiB of heap | 717 | 14700 | -| 4 KiB written again, unchanged | 376 | 24000 | -| 4 KiB of new bytes | 12078 | 584000 | +| a mark | 24 | 290 | +| a step with registers | 51 | 750 | +| ... and a word pushed on the stack | 65 | 450 | +| a word written somewhere in 1 MiB of heap | 320 | 9500 | +| 4 KiB written again, unchanged | 370 | 22000 | +| 4 KiB of new bytes | 12078 | 545000 | An instruction-level recording of `fib(12)` under ptrace, 142 000 moments -with registers and the stack, is 8 MB at 197 000 moments a second; reading -it back is 178 000 moments a second in order, a millisecond to any one. +with registers and the stack, is 8 MB at 197 000 moments a second. Reading +is 6 µs a moment in order and a millisecond to any moment (three at worst). Scattered writes and new bulk data are what cost: each chunk of 64 bytes that changed is written at the next keyframe with its path in the tree. +A larger program, to scale by: Lua 5.4 compiled by `ztrace cc` with +everything instrumented (lines, calls, variables, stores, in all of its +26 000 lines) and run on a ten-line script that takes it a millisecond. + +| what is instrumented | moments | events | recording | run | +| --- | --- | --- | --- | --- | +| everything | 3 248 000 | 7 353 000 | 156 MB | 1.7 s | +| `--only luaV_execute` (the interpreter's loop) | 2 176 000 | 4 640 000 | 93 MB | 1.0 s | +| `--instr calls` | 189 000 | 191 000 | 7 MB | 0.06 s | + +A moment a C line of an interpreter is a great many moments: choose what +is instrumented (`--only`, `--mem`, `--instr`) before choosing to wait. + ## Together The backends are not modes to choose between: they feed one sink. A diff --git a/src/trace/store.zig b/src/trace/store.zig index 8d01570..c8c32e7 100644 --- a/src/trace/store.zig +++ b/src/trace/store.zig @@ -3,7 +3,7 @@ //! //! root = map { //! moments list of bytes: a moment's events, encoded (`Codec`) -//! keys list of keyframe, one a batch of moments +//! keys list of keyframe, one a batch of moments (4096) //! } //! keyframe = map { //! moment the last moment it holds @@ -339,9 +339,11 @@ pub const Recorder = struct { cut: u64 = Kind.step.bit() | Kind.breakpoint.bit() | Kind.syscall_exit.bit() | Kind.signal.bit() | Kind.exit.bit() | Kind.line.bit() | Kind.mark.bit(), /// ... or when its events pass this many bytes. max_delta: usize = 1 << 20, - /// Moments a keyframe, at most: what a reader replays to reach one. A - /// crash loses the batch being gathered. - batch: usize = 256, + /// Moments a keyframe, at most: what a reader replays to reach one (a + /// millisecond, measured), and what a crash loses. Fewer would be seeked + /// to faster and cost more: at 256 the keyframes were half of a + /// recording of Lua. + batch: usize = 4096, /// The file may grow this large; past it `emit` is `error.RecordingFull`. /// A recording is meant to be megabytes: reaching this means too much is /// being recorded (every instruction of a long run, whole buffers). |
