From f1d225020ae68b789b663b7b0637ac52c0a38a05 Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Wed, 5 Aug 2026 14:32:36 -0400 Subject: [PATCH] core: avoid allocating for small pwd change actions Surface.handleMessage allocated a null-terminated copy for every working directory update. Use a small 256-byte stack-fallback buffer for common working directory lengths without adding significant pressure to this deep call stack. Longer paths retain the existing heap behavior, and performAction continues to borrow the value only for the duration of the call. --- src/Surface.zig | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index d3eeff48d..869bf509b 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -1073,9 +1073,10 @@ pub fn handleMessage(self: *Surface, msg: Message) !void { .pwd_change => |w| { defer w.deinit(); - // We always allocate for this because we need to null-terminate. - const str = try self.alloc.dupeZ(u8, w.slice()); - defer self.alloc.free(str); + var stack = std.heap.stackFallback(256, self.alloc); + const alloc = stack.get(); + const str = try alloc.dupeZ(u8, w.slice()); + defer alloc.free(str); _ = try self.rt_app.performAction( .{ .surface = self },