From 0e1d8bd42467c934add371e5ec7758f2b5b70710 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Fri, 23 Jan 2026 15:59:07 -0800 Subject: [PATCH] pull out temporary fixed buffer allocator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit performance now almost twice as fast as json: Benchmark 1: /home/lobo/shared/srf/zig-out/bin/srf srf <.zig-cache/o/51f43613e6e43ed5/test-srf-compact.srf Time (mean ± σ): 65.2 ms ± 4.0 ms [User: 37.6 ms, System: 27.5 ms] Range (min … max): 60.7 ms … 79.6 ms 45 runs Benchmark 2: /home/lobo/shared/srf/zig-out/bin/srf srf <.zig-cache/o/c105a3d3b0472f2e/test-srf-long.srf Time (mean ± σ): 67.8 ms ± 3.5 ms [User: 38.8 ms, System: 29.0 ms] Range (min … max): 63.5 ms … 76.6 ms 42 runs Benchmark 3: /home/lobo/shared/srf/zig-out/bin/srf json <.zig-cache/o/cb2a4e8b89e72422/test-json.json Time (mean ± σ): 126.0 ms ± 3.8 ms [User: 77.6 ms, System: 48.4 ms] Range (min … max): 120.9 ms … 135.3 ms 22 runs Summary /home/lobo/shared/srf/zig-out/bin/srf srf <.zig-cache/o/51f43613e6e43ed5/test-srf-compact.srf ran 1.04 ± 0.08 times faster than /home/lobo/shared/srf/zig-out/bin/srf srf <.zig-cache/o/c105a3d3b0472f2e/test-srf-long.srf 1.93 ± 0.13 times faster than /home/lobo/shared/srf/zig-out/bin/srf json <.zig-cache/o/cb2a4e8b89e72422/test-json.json Prior to this change: Benchmark 1: /home/lobo/shared/srf/zig-out/bin/srf srf <.zig-cache/o/51f43613e6e43ed5/test-srf-compact.srf Time (mean ± σ): 98.9 ms ± 2.8 ms [User: 51.3 ms, System: 47.7 ms] Range (min … max): 95.4 ms … 106.6 ms 29 runs Benchmark 2: /home/lobo/shared/srf/zig-out/bin/srf srf <.zig-cache/o/c105a3d3b0472f2e/test-srf-long.srf Time (mean ± σ): 103.1 ms ± 3.4 ms [User: 53.8 ms, System: 49.4 ms] Range (min … max): 99.0 ms … 112.8 ms 28 runs Benchmark 3: /home/lobo/shared/srf/zig-out/bin/srf json <.zig-cache/o/cb2a4e8b89e72422/test-json.json Time (mean ± σ): 122.6 ms ± 4.4 ms [User: 75.1 ms, System: 47.6 ms] Range (min … max): 117.7 ms … 130.7 ms 22 runs Summary /home/lobo/shared/srf/zig-out/bin/srf srf <.zig-cache/o/51f43613e6e43ed5/test-srf-compact.srf ran 1.04 ± 0.04 times faster than /home/lobo/shared/srf/zig-out/bin/srf srf <.zig-cache/o/c105a3d3b0472f2e/test-srf-long.srf 1.24 ± 0.06 times faster than /home/lobo/shared/srf/zig-out/bin/srf json <.zig-cache/o/cb2a4e8b89e72422/test-json.json --- src/main.zig | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main.zig b/src/main.zig index bcdfefd..7dbfa9b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -76,15 +76,8 @@ pub fn main() !void { try stdin.appendRemaining(base_allocator, &data, @enumFromInt(100 * 1024 * 1024)); if (std.mem.eql(u8, format, "srf")) { - // TODO: Remove this code. SRF should be using an Arena allocator instead - const buffer = try base_allocator.alloc(u8, 200 * 1024 * 1024); - defer base_allocator.free(buffer); - var fba = std.heap.FixedBufferAllocator.init(buffer); - const srf_allocator = fba.allocator(); - // remove ^^ - var reader = std.Io.Reader.fixed(data.items); - const records = try srf.parse(&reader, srf_allocator, .{}); + const records = try srf.parse(&reader, allocator, .{}); defer records.deinit(); } else if (std.mem.eql(u8, format, "jsonl")) { var lines = std.mem.splitScalar(u8, data.items, '\n');