Skip to content

Data: Persistence: Run persistence subscriber on idle callback#16657

Closed
aduth wants to merge 3 commits intomasterfrom
update/persistence-idle-callback
Closed

Data: Persistence: Run persistence subscriber on idle callback#16657
aduth wants to merge 3 commits intomasterfrom
update/persistence-idle-callback

Conversation

@aduth
Copy link
Copy Markdown
Member

@aduth aduth commented Jul 18, 2019

This pull request seeks to optimize the implementation of the data persistence plugin to occur asynchronously in response to a state change only at the earliest idle opportunity. Persistence should occur after a state change, but does not need to occur immediately / synchronously. By deferring the work, we lessen the total workload necessary for each state change.

Work in Progress:

  • The unit tests still need to be updated for the changed behavior.
  • Measure performance impact

Testing Instructions:

Ensure unit tests pass:

npm run test-unit

Verify that changes in preferences (e.g. top toolbar option) persist across page reloads.

@aduth aduth added [Status] In Progress Tracking issues with work in progress [Type] Performance Related to performance efforts [Package] Data /packages/data labels Jul 18, 2019
@aduth aduth requested review from nerrad and youknowriad as code owners July 18, 2019 09:10
@aduth aduth force-pushed the update/persistence-idle-callback branch from 322b6bf to f1a3156 Compare January 16, 2020 20:30
@aduth aduth removed the [Status] In Progress Tracking issues with work in progress label Jan 16, 2020
@aduth
Copy link
Copy Markdown
Member Author

aduth commented Jan 16, 2020

I refreshed this and updated unit tests using a pattern for mocking requestIdleCallback that I implemented in #19282. The tests should now pass again.

However, I'm going to close this out for the following reasons:

  • I was unable to demonstrate a compelling performance benefit. I've had difficulty with testing performance in the past, but at least my attempts to measure change via npm run test-performance yields little-to-no-difference.
    • Conceptually, I still feel that this should have a pretty noticeable difference, given that the logic within the callback is called for every state change to every store (every keystroke when typing within a paragraph).
  • The implications of asynchronous/eventual persistence may be undesirable, since it runs the risk that persistence may not actually happen if the user closes the page before the idle callback is invoked. For something like a change in a user's preference, the user would expect that if the UI is updated to reflect their new preference, it will have been guaranteed to have been committed.

@aduth aduth closed this Jan 16, 2020
@aduth aduth deleted the update/persistence-idle-callback branch January 16, 2020 20:41
@aduth
Copy link
Copy Markdown
Member Author

aduth commented Jan 16, 2020

@ellatrix I know you've been thinking about performance quite a bit lately, so while I don't know that there's anything else to be done around this, I wanted to get it on your radar in case it might strike any inspiration or if you have any thoughts.

@ellatrix
Copy link
Copy Markdown
Member

Thanks for sharing! I've not really looked at this side of performance so much yet. I do know that @youknowriad recently had the idea to allow batching dispatching actions, which would allow us to batch onChange and onSelectionChange from RichText. Perhaps this is slightly related.

@youknowriad
Copy link
Copy Markdown
Contributor

had the idea to allow batching dispatching actions, which would allow us to batch onChange and onSelectionChange from RichText. Perhaps this is slightly related.

I actually tried this, it was super easy to implement. I didn't notice a big difference in performance (probably due to all the recent refactors), so I though it was not worth it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Data /packages/data [Type] Performance Related to performance efforts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants