diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-23 12:13:42 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-23 12:45:04 -0300 |
| commit | de0b9a53ad18555708121b31a3dc813cbda8fa0e (patch) | |
| tree | 50cd96f19ef26baf6fcf37e3f40abce3c181fee9 | |
| parent | 3ea7524ba026f03052e8861c9d4cb18eed8102cb (diff) | |
| download | pardes-de0b9a53ad18555708121b31a3dc813cbda8fa0e.tar.gz pardes-de0b9a53ad18555708121b31a3dc813cbda8fa0e.zip | |
walk: `eql` by the digest's own rules, field by field (a field `replica` leaves out skipped, a `len`-cut array to its length, flat arrays and slices by std.mem.eql, a type that walks itself by its digest), where it took the digest of each: the jump dedupe calls it for every pair on every step, and two Wyhash walks a pair put 32 of pardes-perf's 121 per-operation counts over 0.1% (every key, wheel, page and edit op about +26k instructions, body-appends +1.74M); with this, 120 of 121 within 0.1%, body-appends on longline +0.1001% and on small, medium, large +0.067% (the same +14.5k instructions an op: the dedupe deciding as the digest does where the base's release garbage decided otherwise; every body-appends setup cheaper), everything else within 0.02% (against tree6, load 4.2-4.6); core-test 926/1090 (164 skipped), shell-test 1132/1135 (3 skipped) in Debug (loads 5.0-10.2)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
| -rw-r--r-- | core/walk.zig | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/core/walk.zig b/core/walk.zig index 898a7cf7..593532f8 100644 --- a/core/walk.zig +++ b/core/walk.zig @@ -89,13 +89,43 @@ pub fn digest(comptime T: type, v: *const T) u64 { return h.final(); } -/// Equal as the digest sees them: what the walk leaves out (a Buf's bytes -/// past its length, a cache) is not compared. std.meta.eql compares every -/// byte of an array, and those bytes are undefined: 0xAA on every Debug -/// process, each release process's own garbage; a decision of the core -/// taken on them agrees between a session and its clients in Debug alone. +/// Equal as the digest sees them, by the digest's rules: what the walk +/// leaves out (a field `replica` names, a Buf's bytes past its length) is +/// not compared; a type that walks itself, by its digest. std.meta.eql +/// compares every byte of an array, and those bytes are undefined: 0xAA on +/// every Debug process, each release process's own garbage; a decision of +/// the core taken on them agrees between a session and its clients in +/// Debug alone. pub fn eql(comptime T: type, a: *const T, b: *const T) bool { - return digest(T, a) == digest(T, b); + switch (@typeInfo(T)) { + .void => return true, + .bool, .int, .@"enum" => return a.* == b.*, + .optional => |o| return if (a.*) |*x| (if (b.*) |*y| eql(o.child, x, y) else false) else b.* == null, + .array => |arr| { + if (comptime flatHash(arr.child)) return std.mem.eql(arr.child, a, b); + for (a, b) |*x, *y| if (!eql(arr.child, x, y)) return false; + return true; + }, + .@"struct" => |s| { + if (comptime machinery(T)) return true; + if (comptime s.layout == .@"packed" or @hasDecl(T, "digest") or isList(T) or isAtomic(T) or isBitset(T) or @hasField(T, "any_future")) return digest(T, a) == digest(T, b); + inline for (s.field_names, s.field_types, s.field_attrs) |name, F, attr| { + if (attr.@"comptime" or comptime excluded(T, name)) continue; + if (comptime lengthOf(T, name)) |len| { + const x = @field(a, name)[0..lengthIn(a, len)]; + const y = @field(b, name)[0..lengthIn(b, len)]; + if (comptime flatHash(Element(F))) { + if (!std.mem.eql(Element(F), x, y)) return false; + } else { + if (x.len != y.len) return false; + for (x, y) |*p, *q| if (!eql(Element(F), p, q)) return false; + } + } else if (!eql(F, &@field(a, name), &@field(b, name))) return false; + } + return true; + }, + else => return digest(T, a) == digest(T, b), + } } /// A digest of each field `hash` would walk, in order (what a divergence |
