From 0045636495bf2baf77c8b0eb63e45feeffa016ac Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 18 Nov 2026 02:43:11 -0300 Subject: file watch: a text's watch armed over its open (file_watch.applyEffect) no longer reads and hashes the file again to know the disk is still what the open read: readHost keeps, for each of its last eight whole reads, the path, the buffer it returned and the file's identity (inode, size, times) before reading (fs.last_reads), and an arm whose pane's content is that very buffer, unedited, compares the file as it is now with it, reading again (reloadPane) when it changed, or the content came from elsewhere (a slim dump's Restore, which the watch fills from disk); strace: medium.zig opened 3 -> 2 times by a start; tui medium.zig (3.2 MB), perf stat to the kill at the first frame, best of ten interleaved: 55.4M -> 53.6M instructions:u, 10.1 -> 8.8 ms (load 4); tui core-test 819/958 (139 skipped), shell-test 993/996, behaviour-test 269/273 (the four addon ABI tests the base fails), pane-test 180/181, addon-test 5/5, process-test 2 of 144 failed (lspcomplete and lspcompletemoved, the base's); gui unit-test 1582/1590 (the base's), the frame corpus 77/77 against mbase; test/daemon.py, --upgrade (tui and gui, from the base build), --games and --window-clients (its PDF window case run) pass Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/file_watch.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/file_watch.zig') diff --git a/src/file_watch.zig b/src/file_watch.zig index 788bcae1..9bb59683 100644 --- a/src/file_watch.zig +++ b/src/file_watch.zig @@ -561,6 +561,18 @@ pub fn applyEffect( watched.existed = std.hash.Wyhash.hash(0, file.path); return false; }; + // A text armed over its open's bytes, read just now (its content that + // read's very buffer, unedited): the file still what it was before that + // read (the same inode, size and times) needs no reading again. + if (on) if (watches[id]) |*watched| if (core.panes[id]) |pane| if (pane.file) |file| if (filesystem.localPath(file.path)) |native| { + const at = std.hash.Wyhash.hash(0, native); + for (filesystem.last_reads) |r| if (r.path == at and r.bytes == file.content.ptr and r.len == file.content.len and file.revision == 0) { + const now = identify(io, file.path) catch break; + if (!now.eql(r.file)) break; + watched.existed = std.hash.Wyhash.hash(0, file.path); + return false; + }; + }; return on and watches[id] != null and reloadPane(core, io, watches, id, false); } -- cgit v1.3