Skip to content
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

Debounce state updates #3258

Merged
merged 7 commits into from
Mar 28, 2025
Merged

Debounce state updates #3258

merged 7 commits into from
Mar 28, 2025

Conversation

Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Mar 26, 2025

This changes the persisting logic in the Snap Controller to debounce state updates for each Snap individually by 500 milliseconds. This means that if the Snap updates state multiple times within 500 milliseconds, the state is only persisted once, 500 milliseconds after the last update.

Copy link

codecov bot commented Mar 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.98%. Comparing base (fdc83e1) to head (0b35b76).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3258   +/-   ##
=======================================
  Coverage   94.98%   94.98%           
=======================================
  Files         511      511           
  Lines       11299    11313   +14     
  Branches     1738     1741    +3     
=======================================
+ Hits        10732    10746   +14     
  Misses        567      567           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Mrtenz Mrtenz marked this pull request as ready for review March 26, 2025 10:16
@Mrtenz Mrtenz requested a review from a team as a code owner March 26, 2025 10:16
hmalik88
hmalik88 previously approved these changes Mar 26, 2025
@Mrtenz Mrtenz marked this pull request as draft March 26, 2025 11:50
@Mrtenz
Copy link
Member Author

Mrtenz commented Mar 26, 2025

Marking as draft because this needs some further discussion about the debounce timeout.

@Mrtenz Mrtenz marked this pull request as ready for review March 27, 2025 08:42
@GuillaumeRx
Copy link
Contributor

Does this means we merge updates or that we skip one if they are sent too close to each others ?

@Mrtenz
Copy link
Member Author

Mrtenz commented Mar 27, 2025

Does this means we merge updates or that we skip one if they are sent too close to each others ?

@GuillaumeRx We always persist the entire state object, not partial updates. If there are multiple state updates in a row, we only persist the last (most up to date) one now.

@GuillaumeRx
Copy link
Contributor

Does this means we merge updates or that we skip one if they are sent too close to each others ?

@GuillaumeRx We always persist the entire state object, not partial updates. If there are multiple state updates in a row, we only persist the last (most up to date) one now.

I guess this is okay as this does not really change how the API previously worked but I'm worried that Snaps making multiple non-related updates to the state in a row might start having some state updates missing ? 🤔

@FrederikBolding
Copy link
Member

Does this means we merge updates or that we skip one if they are sent too close to each others ?

@GuillaumeRx We always persist the entire state object, not partial updates. If there are multiple state updates in a row, we only persist the last (most up to date) one now.

I guess this is okay as this does not really change how the API previously worked but I'm worried that Snaps making multiple non-related updates to the state in a row might start having some state updates missing ? 🤔

It should only be the persistence that is affected, the actual state update is put into memory right away

@Mrtenz Mrtenz requested a review from FrederikBolding March 28, 2025 09:13
@Mrtenz Mrtenz force-pushed the mrtenz/debounce-state-updates branch from c24a7f4 to 5a19f0c Compare March 28, 2025 09:16
newSnapState,
encrypted,
);
readonly #persistSnapState = debounce(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized, we should debounce per Snap ID and encrypted true/false otherwise we will have data loss with this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, didn't think about encrypted true/false.

@Mrtenz Mrtenz enabled auto-merge March 28, 2025 12:31
@Mrtenz Mrtenz added this pull request to the merge queue Mar 28, 2025
Merged via the queue into main with commit c1b55b0 Mar 28, 2025
172 checks passed
@Mrtenz Mrtenz deleted the mrtenz/debounce-state-updates branch March 28, 2025 12:42
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.

4 participants