Skip to content

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

Description

@mallenexpensify

Creating this in E/App repo from this issue in the E/react-native-onyx repo, in case an external contributor can work on it.

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

Expensify/react-native-onyx#118

cc @marcaaron

Activity

  1. MelvinBot commented on Mar 1, 2022

    @MelvinBot
    Contributor

    Triggered auto assignment to @CortneyOfstad (AutoAssignerTriage), see https://stackoverflow.com/c/expensify/questions/4749 for more details.

  2. removed
    AutoAssignerTriageAuto assign issues for triage to an available triage team member
    on Mar 1, 2022
  3. removed their assignment
    on Mar 1, 2022
  4. MelvinBot commented on Mar 1, 2022

    @MelvinBot
    Contributor

    Triggered auto assignment to @thienlnam (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

  5. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Mar 1, 2022
  6. MelvinBot commented on Mar 1, 2022

    @MelvinBot
    Contributor

    Triggered auto assignment to @dylanexpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

  7. mallenexpensify commented on Mar 1, 2022

    @mallenexpensify
    ContributorAuthor
  8. dylanexpensify commented on Mar 2, 2022

    @dylanexpensify
    Contributor

    @mallenexpensify am I still good to export this to Upwork?

  9. 34 remaining items

  10. added
    InternalRequires API changes or must be handled by Expensify staff
    and removed
    ExternalAdded to denote the issue can be worked on by a contributor
    on Mar 14, 2022
  11. changed the title [-][$1000] [Performance] localforage.setItem() is causing blocking behavior on init for web clients[/-] [+][Performance] localforage.setItem() is causing blocking behavior on init for web clients[/+] on Mar 15, 2022
  12. marcaaron commented on Mar 23, 2022

    @marcaaron
    Contributor

    a fix should be on staging soon.

  13. marcaaron commented on Mar 31, 2022

    @marcaaron
    Contributor

    Seems like changes are on production now gonna close this!

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

Metadata

Metadata

Assignees

Labels

EngineeringImprovementItem broken or needs improvement.InternalRequires API changes or must be handled by Expensify staffWeeklyKSv2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions