Repository navigation
Description
What happened?
Syncthing on my Mac keeps growing and growing until it's using several GB of memory. It watches one send/receive folder (~665 000 files, a dev workspace, which I know is pretty huge), fully synced and idle, and after four days a heap profile from /rest/debug/heapprof had 3.5 GB live, 99.6% of it in the FSEvents watcher in syncthing/notify (profile below).
The cause is watch.prev in watcher_fsevents.go. It keeps an entry for every path that has ever had a create or remove event and only lets go when the watch stops, so build output that churns through unique filenames piles up forever. Ignored directories count too, because the ignores only get applied after strip has recorded the path. A restart resets it and it starts growing again.
I'd expect the watcher's memory to stay flat no matter how much churn there is.
I have a fix on a branch: https://github.com/fluffypony/notify/tree/fsevents-bounded-history (one commit, fbdebde, which is kinda a wild commit partial hash if you think about it lol). It caps the history at two generations of 8 192 paths and leaves the flag heuristics in strip alone. fseventsd only repeats old flags for a path until it writes out its in-memory records, and it does that at least every 2 730 paths (measured on macOS 26), so anything older than that is safe to forget. With the fix my Syncthing sits at ~6 MB of heap after the startup scan, down from 3.78 GB. The commit has tests, and I have before/after numbers from a churn harness if they're useful - those aren't on the branch, obvs.
Happy to open the PR against syncthing/notify, plus the go.mod bump here, if you want it.
Syncthing version
v2.1.5
Platform & operating system
macOS 26.6.2 (25G83), arm64
Browser version
No response
Relevant log output
$ go tool pprof -top -unit=MB syncthing-heap.pprof
Type: inuse_space
Showing nodes accounting for 3471.70MB, 99.59% of 3486MB total
flat flat% sum% cum cum%
2616.92MB 75.07% 75.07% 2616.92MB 75.07% github.com/syncthing/notify._Cfunc_GoString (inline)
854.78MB 24.52% 99.59% 854.78MB 24.52% github.com/syncthing/notify.(*watch).strip
0 0% 99.59% 3471.70MB 99.59% _cgoexp_b456917c057b_gostream
0 0% 99.59% 854.78MB 24.52% github.com/syncthing/notify.(*watch).Dispatch
Activity
LOCAL-ONLY: bound the FSEvents watcher path history