-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
lib/protocol: Implemented caching of scrypt hashes (fixes #8599) #8600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
calmh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable in general.
lib/util/cache.go
Outdated
|
|
||
| import "sync" | ||
|
|
||
| type Cache[K comparable, V any] struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really just a worse sync.Map, an actual cache would have some max size or invalidation logic etc. Better to use a normal map with a mutex at the call site, or a sync.Map, so that the behavior is clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made some improvements
calmh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like a simpler approach would be to make the existing folderKeyRegistry longer lived than currently (maybe declare one at the top level instead of constructing in NewConnection) and have it key on folder+password (to handle password changes). Having multiple levels of caching seems unnecessarily complicated.
This adds a cache to the expensive key generation operations. It's fixes size LRU/MRU stuff to keep memory usage bounded under absurd conditions. Also closes syncthing#8600.
|
🤖 beep boop I'm going to close this pull request as it has been idle for more than 90 days. This is not a rejection, merely a removal from the list of active pull requests that is periodically reviewed by humans. The pull request can be reopened when there is new activity, and merged once any remaining issues are resolved. To permanently exempt this PR from bot nagging, add the |
With a large number of encrypted folders and devices, they are subject to a large CPU load. Moreover, hashes are recalculated for different devices and for each connection.
Since there can be a limited number of hashes, it was decided to cache them in memory.
Testing
Documentation
Not required
Authorship
Your name and email will be added automatically to the AUTHORS file
based on the commit metadata.