Repository navigation
Conversation
Every FolderSummary, StateChanged and FolderCompletion event triggered a full rehydration, and each rehydration issued /rest/db/status per folder plus /rest/db/completion per folder/device pair. On a folder with ~10^6 items each completion lookup costs seconds of CPU and itself leads to more completion events, keeping Syncthing at several cores while idle. - patch folder status, state and remote sharing state from event payloads - fall back to a full hydration only when a payload is insufficient (unknown folder, error transitions, changed pull error counts) - coalesce structural events into at most one hydration per 5 seconds with a trailing refresh - cache remote sharing states; re-query only after topology events, mutations, reconnects/gaps, or a 15 minute TTL (3 minutes after failures) - emit per-folder StateChanged events in the waybar lifecycle fixture, as Syncthing does, instead of relying on a rehydration side effect Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
@devmil thanks this is a really good catch ! Part of the next release in a couple days I think it's likely I'll reproduce it, and may change a bit in the code , would you mind checking a (potentially) adjusted fix on your side ? Thanks again 👍 |
Author
sure, just let me know |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On a large folder (~960k files, ~1.16M items, 8 GB index database) Syncthing stayed at 150–440% CPU while fully synced and idle, as long as the plugin was running. Pausing
syncshell-corealone brought it down to Syncthing's own baseline.Cause:
requiresHydrationtreats every event except download/item progress as structural.FolderSummary,StateChangedandFolderCompletiontherefore each trigger a fullRefresh. Every refresh calls/rest/db/statusper folder and/rest/db/completionper folder/device pair. On a folder that size, one completion lookup costs several seconds of CPU and is followed by furtherFolderCompletionevents, so the loop never settles. The lookups also often run past the 5 sloadRemoteSharingtimeout, so the remote state staysunknowndespite the cost.Change
FolderSummary(status fields),StateChanged(state) andFolderCompletion(remoteState) are applied directly to the current snapshot, with no REST calls. Counts and revision are updated; an unchanged payload doesn't bump the revision.error, or a changedpullErrorscount (the bounded error list has to be reloaded). This keeps theStateChanged-after-FolderErrorsrecovery behaviour.ConfigSaved,ClusterConfigReceived, device and folder pause/connect events, …) into at most one hydration every 5 s, with a trailing refresh. The 1 s event long-poll lets the trailing refresh run promptly.FolderCompletionevents refresh the cache for free. The cache is cleared on topology events, event gaps or reconnects, and after mutations and ambiguous mutations.refreshIntervalreconciliation and the probe and telemetry schedules are unchanged.Tests
eventpatch_test.go: payload patching, the hydration fallbacks, and an event-loop test showing that a stream of status events causes no/rest/db/statusor/rest/db/completionrequests while 10 structural batches coalesce into 1–3 hydrations.TestRemoteSharingIsCachedUntilInvalidated. The existing sharing tests now invalidate between steps or use distinct folder IDs.TestSharingEventsRefreshRemoteStatenow asserts the new split:ClusterConfigReceivedrehydrates and invalidates, whileFolderCompletionis patched.syncshell-waybarlifecycle fixture: it now also emitsStateChangedforf2, as Syncthing does per folder. Before, it relied on the side effect of a rehydration triggered byf1's event.go vet ./...andgo test -race ./...pass with Go 1.27.3;tests/architecture,native-core-architectureandscriptspass.I didn't rebuild the bundled cores, so they're left to the release build.
Result
On the affected machine, with a build of this change installed, Syncthing went from about 150–440% CPU to its own baseline (about 0–75% in 30 s windows, mostly its own rescans). That matches what it used with the plugin process stopped.
🤖 Generated with Claude Code