From 74236d2db6840c10b5f0a35948fda1b5474346a5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 1 May 2024 19:49:22 -0700 Subject: [PATCH] renderer/metal: log some cache info --- src/font/shaper/Cache.zig | 11 ++++++++++- src/renderer/Metal.zig | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/font/shaper/Cache.zig b/src/font/shaper/Cache.zig index 0571be12d..9da736621 100644 --- a/src/font/shaper/Cache.zig +++ b/src/font/shaper/Cache.zig @@ -16,6 +16,8 @@ const Allocator = std.mem.Allocator; const font = @import("../main.zig"); const lru = @import("../../lru.zig"); +const log = std.log.scoped(.font_shaper_cache); + /// Our LRU is the run hash to the shaped cells. const LRU = lru.AutoHashMap(u64, []font.shape.Cell); @@ -53,10 +55,17 @@ pub fn put( ) Allocator.Error!void { const copy = try alloc.dupe(font.shape.Cell, cells); const gop = try self.map.getOrPut(alloc, run.hash); - if (gop.evicted) |evicted| alloc.free(evicted.value); + if (gop.evicted) |evicted| { + log.debug("evicted shaped cells for text run hash={}", .{run.hash}); + alloc.free(evicted.value); + } gop.value_ptr.* = copy; } +pub fn count(self: *const Cache) usize { + return self.map.map.count(); +} + test Cache { const testing = std.testing; const alloc = testing.allocator; diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index ab53bcc2e..4d91819aa 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -1849,6 +1849,11 @@ fn rebuildCells( x += if (cp.wide) 2 else 1; } } + + // Log some things + log.debug("rebuildCells complete cached_runs={}", .{ + self.font_shaper_cache.count(), + }); } fn updateCell(