From 9f66563479df3b12e08d28fca2bb7bbe4ce65e16 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 2 Aug 2026 09:37:17 -0700 Subject: [PATCH] terminal/snapshot: gate page verification on slow runtime safety PAGE decoding verified the complete native integrity of every decoded page unconditionally, building per-cell reference maps that accounted for roughly a fifth of decode time. The decoder normalizes every semantic value while decoding, so a completed decode upholds page invariants by construction and the verification only defends against decoder bugs. Follow the native page policy instead: assertIntegrity and friends run full verification only when slow runtime safety is enabled, which keeps the check in debug and test builds where those bugs are caught. Benchmark deltas at this commit (terminal-snapshot, 1 MB corpora): ascii lines 1-70: decode 15.5 -> 12.2 ms (encode unchanged) --- src/terminal/snapshot/page.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/terminal/snapshot/page.zig b/src/terminal/snapshot/page.zig index d96e118f5..fb6359455 100644 --- a/src/terminal/snapshot/page.zig +++ b/src/terminal/snapshot/page.zig @@ -93,6 +93,7 @@ //! Rows and cells use the grid encoding documented in `grid.zig`. const std = @import("std"); +const build_options = @import("terminal_options"); const Allocator = std.mem.Allocator; const test_fixture = @import("fixture.zig"); const grid = @import("grid.zig"); @@ -227,7 +228,15 @@ pub const Decoder = struct { self.header, ); try self.record_reader.finish(); - try destination.verifyIntegrity(alloc); + + // The decoder normalizes every semantic value, so a complete decode + // upholds native page invariants by construction. Verifying them + // again is a defense against decoder bugs and follows the native + // page policy: full integrity verification only when slow runtime + // safety is enabled. + if (comptime build_options.slow_runtime_safety) { + try destination.verifyIntegrity(alloc); + } } };