Repository navigation
Filter configuration watcher events without resolving symlinks per event - #1395
Conversation
The watcher added in linearmouse#1209 watched the parent of the configuration directory for every candidate path, so the whole of ~/.config (and ~/Library/Application Support) was streamed, and every unrelated event was canonicalized on the main queue. Watch only the active configuration file's directory and fall back to the nearest existing ancestor while it is missing; the stream narrows back once the directory is recreated. Fixes linearmouse#1368
|
Thanks! It seems that there are two regressions:
|
…symlinks Narrowing the watch to the active file's own directory broke two cases: deleting the higher-priority configuration file no longer reloaded the fallback, and retargeting a symlinked configuration directory stopped hot reload. Restore the previous watch roots and both candidate paths. The CPU cost in linearmouse#1368 came from canonicalizing every event path and refreshing the stream after every callback. FSEvents reports paths with their directories already resolved, so resolve the watched paths once when the stream is updated and compare event paths as reported. Refresh the stream only after an event that touches the watched files. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01MA8JGs7pCoXFL2W6jEJ8sD
|
Thanks, you're right on both. Narrowing the watch was the wrong lever. 7dcbacf goes back to the original watch roots and both candidate paths, and fixes the CPU where it was spent instead: event paths are now compared against paths resolved once when the stream is updated (FSEvents already reports directories resolved), and the stream is only refreshed after an event that touches the configuration files. Both cases have tests now ( |
|
Thanks for the update! Looks good to me. |
Credit to @mhaslinsky for the diagnosis in #1368.
Cause
FileWatcherwatches the parent of each configuration directory, so with~/.config/linearmouse/linearmouse.jsonit receives every event under~/.config(and under~/Library/Application Supportfor the other candidate path). For each callback it canonicalized every event path (readlink/lstat per path component) on the main queue, and then rebuilt the watch roots, before filtering the events out.Fix
The watch roots and the candidate paths stay as they are, so deleting the higher-priority file and retargeting a symlinked configuration directory keep working. Only the filtering changes:
Testing
New
FileWatcherTests: sibling-directory events are not relevant; a symlinked configuration directory is; deleting the higher-priority file is reported; retargeting a symlinked directory is reported, and so is a later edit in the new target.xcodebuild test -project LinearMouse.xcodeproj -scheme LinearMouse -destination 'platform=macOS': 924 tests, 0 failures.FileWatcherTestswith-test-iterations 20: all passed.swiftformat --lintandswiftlint linton the changed files: clean.Command-line harness compiled with
FileWatcher.swift, watching<tmp>/a/linearmouse/linearmouse.jsonand<tmp>/b/linearmouse/linearmouse.jsonwhile a script rewrites files in a siblingother-appdirectory in a tight loop. CPU time fromgetrusageover 15 s:aaandb(b/linearmousemissing)Same harness, both regressions from review: deleting the higher-priority file fires a change callback, and retargeting a symlinked
linearmousedirectory fires one for the retarget and another for a later edit in the new target. Both matchmain.Fixes #1368
🤖 Generated with Claude Code
https://claude.ai/code/session_01MA8JGs7pCoXFL2W6jEJ8sD