From 7ff2368427c2c11488ead052f2fc7f1dd3ff6143 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 5 Nov 2026 12:01:17 -0300 Subject: text journal, a grown text's old buffer given back: a text whose room grows by a copy frees a buffer of a megabyte or more, which an arena keeps resident for the next block its size; memory.trim gives its pages back at once, as a big pane torn down does (a detached session on a 100 MB file, Debug: after typing, twelve 9P edits, undo, redo and a 10 MB cut, 157-166 MB resident where the journal alone left 329 and the snapshots 730; the peak while the copy is made, 328 MB, stays) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/File.zig | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/File.zig b/src/File.zig index 8f3d4bb9..4b73b311 100644 --- a/src/File.zig +++ b/src/File.zig @@ -1004,6 +1004,10 @@ fn grow(gpa: std.mem.Allocator, f: *State, n: usize) !void { pardes.memory.freeRaw(gpa, room); f.content = fresh[0..f.content.len]; f.cap = fresh.len; + // The old buffer's pages back to the system now: an arena keeps a freed + // run of a megabyte or more resident for the next block its size, which + // a text grown with room never asks for (a 100 MB file held its copy). + if (room.len >= 1 << 20) pardes.memory.trim(); } /// `text` with the `len` bytes at `off` replaced by `bytes`, in a new buffer. -- cgit v1.3