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

[Performance] localforage.setItem() is causing blocking behavior on init for web clients #119

Open
marcaaron opened this issue Feb 23, 2022 · 0 comments

Comments

@marcaaron
Copy link
Contributor

Problem

When the app inits and many keys need to be set things get really slow on web. It currently takes me about 10-12 seconds to switch to a new chat when the app inits.

We've narrowed down the source of the problem to:

  1. Not stringifying IndexedDB values. For whatever reason IDB takes a while to store structured JSON.
  2. Calling setItem() too many times in a row

Addressing either one should work. Both seem to be causing similar rates of pain.

Solution

  1. Start stringifying values - complicated because some of the JSON is not serializable i.e. stuff with attachments.
  2. Defer the writing to IndexedDB until we are idle or just slow it down or something at least. We are using a memory cache already so I can't think of a reason why our writes must happen immediately on page load.

More ideas here: https://rxdb.info/slow-indexeddb.html, but the general suggestion is to use fewer transactions. That is not possible with localforage so we might want to look elsewhere - maybe the plugin mentioned here can help localForage/localForage#315

I did a test here where I just made all the writes synchronous (probably not the solution we want), but it improves things immensely

#118

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

No branches or pull requests

1 participant