From ef0de36bf473f22d37cc885054bf4eed98bf275f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 23 Oct 2026 17:11:12 -0300 Subject: Arenas are regions mapped once with a page bitmap under a DebugAllocator; the shells allocate from one too Each arena (pardes, frame, lsp, tree_sitter, image, pdf and the new host) maps its region once and tracks 4 KiB pages in a bitmap; a full region spills to malloc and counts it. Freed runs of 64 KiB to 1 MiB go back at once, the rest at memory.trim. In a release build init.gpa is memory.host over libc's malloc. Measured against the old arenas: typing in a 7.4 MB file 1.95 ms a key (was 2.0), a V8 Callstack page 142 MiB (was 134) and 42 MiB after close (was 69). Co-Authored-By: Claude Opus 5.5 --- src/main.zig | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index 52093b9a..9086fa90 100644 --- a/src/main.zig +++ b/src/main.zig @@ -317,16 +317,13 @@ fn webMain() !void { try @import("gui/gui.zig").run(.{}, .{}, null); } -// init.gpa, what the tty, gui and detached shells allocate from, is -// std.start's: a DebugAllocator in Debug and, since we link libc, libc's -// malloc otherwise. Kept on purpose: glibc's malloc was measured at least as -// fast as std.heap.smp_allocator on every scenario and faster on MuPDF's -// page-sized rasters. macos.zig makes the same choice for itself. +// init.gpa, what the tty, gui and detached shells allocate from, is their +// own fixed arena (memory.host) in a release build, spilling to libc's +// malloc, and std.start's DebugAllocator in Debug. Zig 0.17's std.start +// gives a safe build a SafeAllocator over the page allocator instead. fn nativeMain(std_init: std.process.Init) !void { var init = std_init; - // Zig 0.17's std.start gives a safe build a SafeAllocator over the page - // allocator, not libc's malloc: hand the shells malloc, as above. - if (builtin.mode != .debug) init.gpa = std.heap.c_allocator; + if (builtin.mode != .debug) init.gpa = pardes.memory.host(std.heap.c_allocator); var stderr_probe: [64]u8 = undefined; _ = std.debug.lockStderr(&stderr_probe); std.debug.unlockStderr(); -- cgit v1.3