From 0e302423b5dd0352ae8eec0315b052961495a58a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20Dokumac=C4=B1?= Date: Fri, 31 Jul 2026 17:55:16 +0200 Subject: [PATCH 1/4] chore: fix dead code hunter script --- scripts/unused_pub_detector.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/unused_pub_detector.js b/scripts/unused_pub_detector.js index cdf419f3..e489d335 100644 --- a/scripts/unused_pub_detector.js +++ b/scripts/unused_pub_detector.js @@ -218,9 +218,13 @@ for (const d of decls) { if (d.parent) { const qn = d.parent + "." + d.name; if (isSelf) { - if (hasWordOutsideLines(selfText, qn, [d.line])) { prodCount++; continue; } + if (hasWordOutsideLines(selfText, qn, [d.line])) prodCount++ + else if (hasWord(selfText, d.parent) && hasWordOutsideLines(selfText, d.name, [d.line])) prodCount++; } else { - if (hasWord(getStripped(f), qn)) { + const fText = getStripped(f); + if (hasWord(fText, qn)) { + if (fileType.get(fp) === "prod") prodCount++; else testCount++; + } else if (hasWord(fText, d.parent) && hasWord(fText, d.name)) { if (fileType.get(fp) === "prod") prodCount++; else testCount++; } } From 169d06eb7fd181c03b079a03d1bd38f0a104b4c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20Dokumac=C4=B1?= Date: Fri, 31 Jul 2026 19:14:41 +0200 Subject: [PATCH 2/4] chore: remove entirely dead code --- src/connection/state.zig | 4 -- src/lock_free_cache.zig | 54 -------------------------- src/msgpack_utils.zig | 1 - src/queues/spmc_blocking_queue.zig | 6 --- src/storage_engine.zig | 1 - src/subscription/change_queue_test.zig | 4 +- src/wire/encode.zig | 2 - 7 files changed, 2 insertions(+), 70 deletions(-) diff --git a/src/connection/state.zig b/src/connection/state.zig index bce7ad93..7e88653f 100644 --- a/src/connection/state.zig +++ b/src/connection/state.zig @@ -64,10 +64,6 @@ pub const Outbox = struct { } } - pub fn isEmpty(self: Outbox) bool { - return self.tail == self.head; - } - pub fn isFull(self: Outbox) bool { return (self.head + 1) % outbox_capacity == self.tail; } diff --git a/src/lock_free_cache.zig b/src/lock_free_cache.zig index 4058d8ed..1e45f5f9 100644 --- a/src/lock_free_cache.zig +++ b/src/lock_free_cache.zig @@ -341,55 +341,6 @@ pub fn lockFreeCache(comptime t: type, comptime KeyType: type) type { // zwanzig } } - /// Evict multiple entries from the cache in a single COW operation - pub fn bulkEvict(self: *Self, keys: []const KeyType) void { - if (keys.len == 0) return; - while (true) { - const epoch_slot = self.epoch_manager.enter(); - defer self.epoch_manager.exit(epoch_slot); - - const old_entries = self.entries.load(.acquire); - - var any_exists = false; - for (keys) |key| { - if (old_entries.contains(key)) { - any_exists = true; - break; - } - } - if (!any_exists) return; - - const new_entries = self.cloneEntries(old_entries) catch return; - - var evicted_entries = std.ArrayListUnmanaged(*CacheEntry).initCapacity(self.allocator, keys.len) catch { - new_entries.deinit(); - self.allocator.destroy(new_entries); - return; - }; - defer evicted_entries.deinit(self.allocator); - - for (keys) |key| { - if (new_entries.fetchRemove(key)) |kv| { - evicted_entries.appendAssumeCapacity(kv.value); - } - } - - if (self.entries.cmpxchgStrong(old_entries, new_entries, .acq_rel, .acquire)) |actual| { - _ = actual; - new_entries.deinit(); - self.allocator.destroy(new_entries); - continue; - } else { - for (evicted_entries.items) |e| { - self.internalDefer(.{ .entry = e }); - } - self.internalDefer(.{ .map = old_entries }); - _ = self.epoch_manager.bump(); - return; - } - } - } - fn internalDefer(self: *Self, resource: Resource) void { const node = self.pool.pop() orelse blk: { self.reclaim(false); @@ -432,11 +383,6 @@ pub fn lockFreeCache(comptime t: type, comptime KeyType: type) type { // zwanzig } } - pub fn size(self: *Self) usize { - const map = self.entries.load(.acquire); - return map.count(); - } - pub fn reclaim(self: *Self, force: bool) void { const min_epoch = if (force) std.math.maxInt(u64) else self.epoch_manager.minActiveEpoch(); diff --git a/src/msgpack_utils.zig b/src/msgpack_utils.zig index 5143bfe2..53747849 100644 --- a/src/msgpack_utils.zig +++ b/src/msgpack_utils.zig @@ -3,7 +3,6 @@ const std = @import("std"); const msgpack = @import("msgpack"); pub const Payload = msgpack.Payload; -pub const Map = msgpack.Map; /// Security-appropriate parse limits for WebSocket message handling. /// These align with the ZyncBase Wire Protocol Specification. diff --git a/src/queues/spmc_blocking_queue.zig b/src/queues/spmc_blocking_queue.zig index e4b833f8..a81c045c 100644 --- a/src/queues/spmc_blocking_queue.zig +++ b/src/queues/spmc_blocking_queue.zig @@ -114,12 +114,6 @@ pub fn spmcBlockingQueue(comptime T: type) type { self.cond.broadcast(); } - pub fn isEmpty(self: *Self) bool { - self.mutex.lock(); - defer self.mutex.unlock(); - return self.count == 0; - } - pub fn deinit(self: *Self) void { self.mutex.lock(); defer self.mutex.unlock(); diff --git a/src/storage_engine.zig b/src/storage_engine.zig index df8b12be..77725ee2 100644 --- a/src/storage_engine.zig +++ b/src/storage_engine.zig @@ -36,7 +36,6 @@ pub const AckLatch = write_queue.AckLatch; const CheckpointStats = write_queue.CheckpointStats; pub const write_queue_type = write_queue.write_queue_type; pub const ReadRequest = read_buffer.ReadRequest; -pub const ReadResponse = read_buffer.ReadResponse; const DocId = typed_doc_id.DocId; const metadata_cache_type = storage_cache.metadata_cache_type; const namespace_cache_type = storage_cache.namespace_cache_type; diff --git a/src/subscription/change_queue_test.zig b/src/subscription/change_queue_test.zig index a70ec3e4..154378c3 100644 --- a/src/subscription/change_queue_test.zig +++ b/src/subscription/change_queue_test.zig @@ -125,10 +125,10 @@ test "ChangeQueue: multi-shard init and deinit" { var queue = try ChangeQueue.init(alloc, num_shards); try testing.expectEqual(num_shards, queue.shardCount()); - // Verify each shard is accessible + // Verify each shard is accessible and initially empty for (0..num_shards) |i| { const shard = queue.getShard(i); - try testing.expect(shard.isEmpty()); + try testing.expect(shard.popTimed(0) == null); } queue.deinit(); diff --git a/src/wire/encode.zig b/src/wire/encode.zig index 08b4706e..e4e30de4 100644 --- a/src/wire/encode.zig +++ b/src/wire/encode.zig @@ -35,11 +35,9 @@ const Keys = struct { pub const fields = comptimeEncodeKey("fields"); pub const field_flags = comptimeEncodeKey("fieldFlags"); pub const write_id = comptimeEncodeKey("writeId"); - pub const details = comptimeEncodeKey("details"); pub const phase = comptimeEncodeKey("phase"); pub const batch_index = comptimeEncodeKey("batchIndex"); pub const session = comptimeEncodeKey("session"); - pub const token = comptimeEncodeKey("token"); pub const presence_user_fields = comptimeEncodeKey("presenceUserFields"); pub const presence_shared_fields = comptimeEncodeKey("presenceSharedFields"); pub const event = comptimeEncodeKey("event"); From 2f91db517b5610976143e790e16b8e9ec3948574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20Dokumac=C4=B1?= Date: Fri, 31 Jul 2026 19:41:11 +0200 Subject: [PATCH 3/4] chore: address review comments --- scripts/unused_pub_detector.js | 20 ++++++++++++++++++-- src/subscription/change_queue_test.zig | 9 ++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/scripts/unused_pub_detector.js b/scripts/unused_pub_detector.js index e489d335..28b36e59 100644 --- a/scripts/unused_pub_detector.js +++ b/scripts/unused_pub_detector.js @@ -191,6 +191,22 @@ function hasWord(text, word) { return false; } +function escapeRegex(s) { return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } + +function hasMemberAccess(text, name) { + return new RegExp("\\.\\s*" + escapeRegex(name) + "\\b").test(text); +} + +function hasMemberAccessOutsideLines(text, name, skipLines) { + const re = new RegExp("\\.\\s*" + escapeRegex(name) + "\\b", "g"); + let m; + while ((m = re.exec(text)) !== null) { + const lineIdx = (text.substring(0, m.index).match(/\n/g) || []).length; + if (!skipLines.includes(lineIdx + 1)) return true; + } + return false; +} + // ---- STRIPPED TEXT CACHE (precomputed per-file, reused for self+ref checks) ---- const strippedCache = new Map(); function getStripped(f) { @@ -219,12 +235,12 @@ for (const d of decls) { const qn = d.parent + "." + d.name; if (isSelf) { if (hasWordOutsideLines(selfText, qn, [d.line])) prodCount++ - else if (hasWord(selfText, d.parent) && hasWordOutsideLines(selfText, d.name, [d.line])) prodCount++; + else if (hasWord(selfText, d.parent) && hasMemberAccessOutsideLines(selfText, d.name, [d.line])) prodCount++; } else { const fText = getStripped(f); if (hasWord(fText, qn)) { if (fileType.get(fp) === "prod") prodCount++; else testCount++; - } else if (hasWord(fText, d.parent) && hasWord(fText, d.name)) { + } else if (hasWord(fText, d.parent) && hasMemberAccess(fText, d.name)) { if (fileType.get(fp) === "prod") prodCount++; else testCount++; } } diff --git a/src/subscription/change_queue_test.zig b/src/subscription/change_queue_test.zig index 154378c3..13c0b940 100644 --- a/src/subscription/change_queue_test.zig +++ b/src/subscription/change_queue_test.zig @@ -123,14 +123,17 @@ test "ChangeQueue: multi-shard init and deinit" { // Test various shard counts for ([_]usize{ 1, 2, 4, 8, 16 }) |num_shards| { var queue = try ChangeQueue.init(alloc, num_shards); + defer queue.deinit(); try testing.expectEqual(num_shards, queue.shardCount()); // Verify each shard is accessible and initially empty for (0..num_shards) |i| { const shard = queue.getShard(i); - try testing.expect(shard.popTimed(0) == null); + if (shard.popTimed(0)) |job| { + var mut_job = job; + mut_job.deinit(alloc); + try testing.expect(false); + } } - - queue.deinit(); } } From f8b4eca3150167fb25c241e1a375f94a581621da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20Dokumac=C4=B1?= Date: Fri, 31 Jul 2026 20:27:56 +0200 Subject: [PATCH 4/4] chore: improve the script some more --- scripts/unused_pub_detector.js | 16 +++------------- src/config_loader.zig | 4 ++-- src/memory_strategy.zig | 2 +- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/scripts/unused_pub_detector.js b/scripts/unused_pub_detector.js index 28b36e59..ea4ba465 100644 --- a/scripts/unused_pub_detector.js +++ b/scripts/unused_pub_detector.js @@ -134,8 +134,8 @@ for (const f of prod) { let pm; while ((pm = pubRe.exec(line)) !== null) { const name = pm[2]; - if (depth === 0 && name === "main" && pm[1] === "fn") continue; - if (depth === 0 && name === "std_options") continue; + if (scope.length === 0 && name === "main" && pm[1] === "fn") continue; + if (scope.length === 0 && name === "std_options") continue; if (name === "Self") continue; decls.push({ @@ -197,16 +197,6 @@ function hasMemberAccess(text, name) { return new RegExp("\\.\\s*" + escapeRegex(name) + "\\b").test(text); } -function hasMemberAccessOutsideLines(text, name, skipLines) { - const re = new RegExp("\\.\\s*" + escapeRegex(name) + "\\b", "g"); - let m; - while ((m = re.exec(text)) !== null) { - const lineIdx = (text.substring(0, m.index).match(/\n/g) || []).length; - if (!skipLines.includes(lineIdx + 1)) return true; - } - return false; -} - // ---- STRIPPED TEXT CACHE (precomputed per-file, reused for self+ref checks) ---- const strippedCache = new Map(); function getStripped(f) { @@ -235,7 +225,7 @@ for (const d of decls) { const qn = d.parent + "." + d.name; if (isSelf) { if (hasWordOutsideLines(selfText, qn, [d.line])) prodCount++ - else if (hasWord(selfText, d.parent) && hasMemberAccessOutsideLines(selfText, d.name, [d.line])) prodCount++; + else if (hasWord(selfText, d.parent) && hasWordOutsideLines(selfText, d.name, [d.line])) prodCount++; } else { const fText = getStripped(f); if (hasWord(fText, qn)) { diff --git a/src/config_loader.zig b/src/config_loader.zig index 3201c3a6..2fd4d2c0 100644 --- a/src/config_loader.zig +++ b/src/config_loader.zig @@ -16,7 +16,7 @@ pub const Config = struct { authorization_file: ?[]const u8, allocator: Allocator, - pub const ServerConfig = struct { + const ServerConfig = struct { port: u16 = 3000, host: []const u8 = "0.0.0.0", }; @@ -34,7 +34,7 @@ pub const Config = struct { anonymous_subject_prefix: []const u8, session: SessionConfig = .{}, - pub const SessionConfig = struct { + const SessionConfig = struct { claims: std.StringHashMapUnmanaged([]const u8) = .{}, token_grace_period_seconds: u32 = 30, }; diff --git a/src/memory_strategy.zig b/src/memory_strategy.zig index bb92958a..bb543843 100644 --- a/src/memory_strategy.zig +++ b/src/memory_strategy.zig @@ -27,7 +27,7 @@ pub const MemoryStrategy = struct { arena_pool: PoolConfig = .{ .pre_allocate = 1024, .max_capacity = 1024 }, connection_pool: PoolConfig = .{ .pre_allocate = 0, .max_capacity = 100_000 }, - pub const PoolConfig = struct { + const PoolConfig = struct { pre_allocate: u32, max_capacity: u32, };