Repository navigation
Conversation
|
This was found while looking for reasons as to why syncthing is using +30GB of RAM when a shared folder has +1 million files. |
There was a problem hiding this comment.
Pull request overview
This PR refines rename detection during folder scanning to reduce memory usage and avoid unbounded growth of in-memory tracking state across long scans, while preserving correct rename-consumption semantics.
Changes:
- Limit rename tracking to only names involved in accepted rename matches (sources/destinations), rather than recording every scanned filename.
- Reset rename-tracking state at
FileInfoBatchflush boundaries to keep the tracking map scoped to the buffered update window. - Add a regression test ensuring a consumed rename source is not reused for multiple destinations within the same tracking window.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/model/folder.go | Adjusts rename tracking map semantics and resets it at batch flush boundaries; tightens when candidates are marked “used”. |
| lib/model/model_test.go | Adds a test to assert rename-source consumption is not reused across multiple destinations with identical content. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Tracks names participating in successful rename detection within the | ||
| // current update batch. We intentionally don't track every scanned file, | ||
| // only consumed rename sources and destinations. | ||
| alreadyUsedOrExisting := make(map[string]struct{}) |
| // Rename tracking only needs to deduplicate source/destination use | ||
| // while updates are buffered. Once flushed, persisted state keeps | ||
| // rename source consumption correct, so we can safely reset. | ||
| clear(alreadyUsedOrExisting) |
Inspired by the report in syncthing#10652. Signed-off-by: Jakob Borg <[email protected]>
calmh
left a comment
There was a problem hiding this comment.
Thanks for the report. I'm writing a slightly different, non-AI, take on the fix.
Sounds good to me! Feel free to close this one. |
Purpose
Description
scanSubdirsChangedAndNewreplaced eager insertion of scanned/self-matching names with a map that only tracks names consumed by successful rename detection, and added a comment documenting the intent.FileInfoBatchflush boundary the rename-tracking map is reset by detectingupdateBatch.Full()beforeFlushIfFull()and clearing the map when a flush occurs, with an inline correctness note.findRenameremoved the insertion on self-match (fi.Name == file.Name) and avoided marking non-deleted or otherwise unsuitable candidates as used, and only mark the source and destination names in the tracking map when a rename match is actually accepted.TestFindRenameDoesNotReuseConsumedSourcetomodel_test.goto assert that a rename source consumed for one destination is not reused for a second destination with identical content.Testing
go test ./lib/model -run 'TestRenameSameFile|TestFindRenameDoesNotReuseConsumedSource'and the tests passed (ok).Note: This bug and fix was found and produced by Codex using
gpt-5.3-codex.