-
Notifications
You must be signed in to change notification settings - Fork 618
Cache snap state in memory #2980
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
19202f3
to
1a95f6b
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2980 +/- ##
==========================================
+ Coverage 94.74% 94.75% +0.01%
==========================================
Files 497 497
Lines 10868 10896 +28
Branches 1669 1674 +5
==========================================
+ Hits 10297 10325 +28
Misses 571 571 ☔ View full report in Codecov by Sentry. |
2c7f8fa
to
cd4b9b3
Compare
Updated dependencies detected. Learn more about Socket for GitHub ↗︎
|
encrypted: boolean, | ||
) { | ||
const runtime = this.#getRuntimeExpect(snapId); | ||
await runtime.stateMutex.runExclusive(async () => { |
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.
Technically we would probably only need a mutex for encrypted storage since regular storage is synchronous? Do you think it is preferable to have both operations under the same mutex?
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.
The call to #persistSnapState
is asynchronous, so to avoid possible race conditions, I think this makes sense?
To improve performance when using state, especially when using the new state methods (#2916), we now cache state in memory, and write updates to disk asynchronously. The first time the state is fetched, it's cached in the Snap's runtime data, which is used in subsequent calls.
To improve performance when using state, especially when using the new state methods (#2916), we now cache state in memory, and write updates to disk asynchronously. The first time the state is fetched, it's cached in the Snap's runtime data, which is used in subsequent calls.