Skip to content

Conversation

Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Jan 7, 2025

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.

@Mrtenz Mrtenz force-pushed the mrtenz/cache-state branch from 19202f3 to 1a95f6b Compare January 8, 2025 13:06
Copy link

codecov bot commented Jan 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.75%. Comparing base (e68e282) to head (6d5edf7).
Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@Mrtenz Mrtenz marked this pull request as ready for review January 8, 2025 13:40
@Mrtenz Mrtenz requested a review from a team as a code owner January 8, 2025 13:40
@Mrtenz Mrtenz force-pushed the mrtenz/cache-state branch from 2c7f8fa to cd4b9b3 Compare January 10, 2025 11:34
Copy link

socket-security bot commented Jan 10, 2025

Updated dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/async-mutex@0.5.0 🔁 npm/async-mutex@0.4.1 None 0 63 kB dirtyhairy

View full report↗︎

encrypted: boolean,
) {
const runtime = this.#getRuntimeExpect(snapId);
await runtime.stateMutex.runExclusive(async () => {
Copy link
Member

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?

Copy link
Member Author

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?

@Mrtenz Mrtenz merged commit 6861362 into main Jan 13, 2025
166 checks passed
@Mrtenz Mrtenz deleted the mrtenz/cache-state branch January 13, 2025 11:35
PatrykLucka pushed a commit that referenced this pull request Jan 13, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants