From 8824256059d130a48d9daa4b489de21a043cfcd2 Mon Sep 17 00:00:00 2001 From: Jesse Miller Date: Fri, 5 Sep 2025 13:34:10 -0600 Subject: [PATCH] Micro-optimize GlyphKey Context Use fast hash function on key for better distribution. Direct compare glyph in eql to avoid Packed.from() if not neccessary. 16% -> 6.4% reduction during profiling runs. --- src/font/SharedGrid.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/font/SharedGrid.zig b/src/font/SharedGrid.zig index 980b0314c..ff05d1a59 100644 --- a/src/font/SharedGrid.zig +++ b/src/font/SharedGrid.zig @@ -332,11 +332,12 @@ const GlyphKey = struct { const Context = struct { pub fn hash(_: Context, key: GlyphKey) u64 { - return @bitCast(Packed.from(key)); + const packed_key = Packed.from(key); + return std.hash.CityHash64.hash(std.mem.asBytes(&packed_key)); } pub fn eql(_: Context, a: GlyphKey, b: GlyphKey) bool { - return Packed.from(a) == Packed.from(b); + return a.glyph == b.glyph and Packed.from(a) == Packed.from(b); } };