Skip to content

Commit 26c2456

Browse files
remove unused code and fix types
1 parent db547ca commit 26c2456

14 files changed

Lines changed: 431 additions & 750 deletions

benchmarks/isolated.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn main() !void {
2121
zlog.field.string("user_id", "12345"),
2222
zlog.field.string("action", "login"),
2323
zlog.field.int("ts", @as(i64, @intCast(i))),
24-
}) catch unreachable;
24+
}) catch @panic("isolated serialization buffer overflow");
2525
serialize_ns += @as(u64, @intCast(support.nowNs() - start));
2626
}
2727

@@ -37,7 +37,7 @@ pub fn main() !void {
3737
var mutex: std.Io.Mutex = .init;
3838
for (0..iterations) |_| {
3939
const start = support.nowNs();
40-
mutex.lock(io) catch unreachable;
40+
mutex.lock(io) catch @panic("isolated mutex lock failed");
4141
std.mem.doNotOptimizeAway(dummy_json.len);
4242
mutex.unlock(io);
4343
mutex_ns += @as(u64, @intCast(support.nowNs() - start));

benchmarks/memory.zig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub fn main() !void {
1111

1212
const iterations = 50_000;
1313
const zlog_ns = benchZlog(iterations);
14-
const alloc_print_ns = benchAllocPrint(allocator, iterations);
15-
const buf_print_ns = benchBufPrint(iterations);
14+
const alloc_print_ns = try benchAllocPrint(allocator, iterations);
15+
const buf_print_ns = try benchBufPrint(iterations);
1616

1717
printCase("zlog sync logger", iterations, zlog_ns);
1818
printCase("std.fmt.allocPrint", iterations, alloc_print_ns);
@@ -41,32 +41,32 @@ fn benchZlog(iterations: usize) i128 {
4141
return support.nowNs() - start;
4242
}
4343

44-
fn benchAllocPrint(allocator: std.mem.Allocator, iterations: usize) i128 {
44+
fn benchAllocPrint(allocator: std.mem.Allocator, iterations: usize) !i128 {
4545
const start = support.nowNs();
4646
for (0..iterations) |i| {
47-
const line = std.fmt.allocPrint(
47+
const line = try std.fmt.allocPrint(
4848
allocator,
4949
"{{\"level\":\"Info\",\"message\":\"User action\",\"user_id\":\"12345\",\"action\":\"login\",\"timestamp\":{d}}}\n",
5050
.{i},
51-
) catch unreachable;
51+
);
5252
allocator.free(line);
5353
}
5454
return support.nowNs() - start;
5555
}
5656

57-
fn benchBufPrint(iterations: usize) i128 {
57+
fn benchBufPrint(iterations: usize) !i128 {
5858
var sink_buffer: [256]u8 = undefined;
5959
var sink = std.Io.Writer.Discarding.init(&sink_buffer);
6060
var line_buffer: [160]u8 = undefined;
6161

6262
const start = support.nowNs();
6363
for (0..iterations) |i| {
64-
const line = std.fmt.bufPrint(
64+
const line = try std.fmt.bufPrint(
6565
&line_buffer,
6666
"{{\"level\":\"Info\",\"message\":\"User action\",\"user_id\":\"12345\",\"action\":\"login\",\"timestamp\":{d}}}\n",
6767
.{i},
68-
) catch unreachable;
69-
sink.writer.writeAll(line) catch unreachable;
68+
);
69+
try sink.writer.writeAll(line);
7070
}
7171
return support.nowNs() - start;
7272
}

benchmarks/production.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ fn runWorkload(logger: anytype, request_count: usize) BenchmarkResult {
7171
const req_start = support.nowNs();
7272

7373
var request_id_buffer: [24]u8 = undefined;
74-
const request_id = std.fmt.bufPrint(&request_id_buffer, "req-{d}", .{i}) catch unreachable;
74+
const request_id = std.fmt.bufPrint(&request_id_buffer, "req-{d}", .{i}) catch {
75+
@panic("request id buffer overflow");
76+
};
7577
const method = if (i % 3 == 0) "POST" else "GET";
7678
const endpoint = switch (i % 4) {
7779
0 => "/api/users",

benchmarks/redaction.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ pub fn main() !void {
88
std.debug.print("=== Redaction Benchmark ===\n\n", .{});
99

1010
const baseline_ns = benchmarkBaseline(150_000);
11-
const redacted_ns = benchmarkWithRedaction(150_000);
12-
const dense_redaction_ns = benchmarkDenseRedaction(150_000);
11+
const redacted_ns = try benchmarkWithRedaction(150_000);
12+
const dense_redaction_ns = try benchmarkDenseRedaction(150_000);
1313

1414
printCase("baseline", 150_000, baseline_ns);
1515
printCase("runtime redaction", 150_000, redacted_ns);
@@ -36,12 +36,12 @@ fn benchmarkBaseline(iterations: usize) i128 {
3636
return support.nowNs() - start;
3737
}
3838

39-
fn benchmarkWithRedaction(iterations: usize) i128 {
39+
fn benchmarkWithRedaction(iterations: usize) !i128 {
4040
var redaction_storage: [8][]const u8 = undefined;
4141
var redaction_config = zlog.RedactionConfig.init(&redaction_storage);
4242
defer redaction_config.deinit();
43-
redaction_config.addKey("password") catch unreachable;
44-
redaction_config.addKey("api_key") catch unreachable;
43+
try redaction_config.addKey("password");
44+
try redaction_config.addKey("api_key");
4545

4646
var sink_buffer: [256]u8 = undefined;
4747
var sink = std.Io.Writer.Discarding.init(&sink_buffer);
@@ -62,12 +62,12 @@ fn benchmarkWithRedaction(iterations: usize) i128 {
6262
return support.nowNs() - start;
6363
}
6464

65-
fn benchmarkDenseRedaction(iterations: usize) i128 {
65+
fn benchmarkDenseRedaction(iterations: usize) !i128 {
6666
var redaction_storage: [16][]const u8 = undefined;
6767
var redaction_config = zlog.RedactionConfig.init(&redaction_storage);
6868
defer redaction_config.deinit();
6969
for ([_][]const u8{ "ssn", "credit_card", "cvv", "pin", "password", "api_key", "secret_token" }) |key| {
70-
redaction_config.addKey(key) catch unreachable;
70+
try redaction_config.addKey(key);
7171
}
7272

7373
var sink_buffer: [256]u8 = undefined;

benchmarks/support.zig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ pub fn runtimeIo() std.Io {
55
}
66

77
pub fn nowNs() i128 {
8-
return @as(i128, std.Io.Timestamp.now(runtimeIo(), .awake).nanoseconds);
8+
return std.Io.Timestamp.now(runtimeIo(), .awake).nanoseconds;
99
}
1010

1111
pub fn nowMs() i64 {
1212
return std.Io.Timestamp.now(runtimeIo(), .real).toMilliseconds();
1313
}
1414

1515
pub fn sleepMs(ms: i64) void {
16-
runtimeIo().sleep(.fromMilliseconds(ms), .awake) catch {};
16+
runtimeIo().sleep(.fromMilliseconds(ms), .awake) catch |err| {
17+
std.debug.panic("benchmark sleep failed: {}", .{err});
18+
};
1719
}
1820

1921
pub fn nsToMs(ns: i128) f64 {
@@ -59,8 +61,8 @@ pub const LatencyWriter = struct {
5961
};
6062

6163
fn busyWait(io: std.Io, ns: i128) void {
62-
const start = @as(i128, std.Io.Timestamp.now(io, .awake).nanoseconds);
63-
while (@as(i128, std.Io.Timestamp.now(io, .awake).nanoseconds) - start < ns) {
64+
const start: i128 = std.Io.Timestamp.now(io, .awake).nanoseconds;
65+
while (std.Io.Timestamp.now(io, .awake).nanoseconds - start < ns) {
6466
std.atomic.spinLoopHint();
6567
}
6668
}

build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const std = @import("std");
22

3-
const version = std.SemanticVersion{ .major = 0, .minor = 3, .patch = 0 };
3+
const version = std.SemanticVersion{ .major = 0, .minor = 4, .patch = 0 };
44

55
pub fn build(b: *std.Build) void {
66
const target = b.standardTargetOptions(.{});

src/async_batcher.zig

Lines changed: 0 additions & 230 deletions
This file was deleted.

0 commit comments

Comments
 (0)