WIP proposal: debounce background store updates to UI #3535
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.
This is in many ways a much more targeted version of #1296 .
The observation feeding this PR is that the most expensive part of redux work right now is:
Doing this whole cycle on every action means that we can't structure actions freely, because we trigger the whole cycle on every action. We've experimented in the past with debouncing actions and subscribers at the cross-redux store level, but very quickly ran into edge cases with what happens on unsubscribe, timing issues, etc.
This approach eliminates all of that by only debouncing the state updates being pushed out by webext-redux. We do this by abusing the diff function on the background script side. The diff function now branches in two ways:
The diff only affects the UI states, not the background state—the background state is wholly managed by redux. The old state tracked by webext-redux only changes when the diff is non-empty. We use these two facts to create a single batch of changes at most every 300ms (hardcoded right now).
This commit needs a little cleanup and a message that looks more like this PR description.
Latest build: extension-builds-3535 (as of Fri, 07 Jul 2023 14:11:40 GMT).