Skip to content

Major performance issues can result from batching #1645

@lucasyvas

Description

@lucasyvas

Describe the bug

Critical UI updates derived from queries can be batched into later cycles, creating a detrimental experience. We have a fairly large component that shows loading spinners derived from isLoading. We are using a mix of useQuery and useQueries, and unfortunately the internal batching strategy can lead to more critical visual updates being delayed. In this case, fewer re-renders is not good, as they occur near the tail end.

To Reproduce

There may be several variables, but here is our scenario:

  1. A large table with many rows
  2. Rows can display a loading spinner derived from isLoading status
  3. Loading spinner display is heavily delayed, due to batching
  4. UX suffers

Expected behavior

I expect to be able to control data/renders in my own hooks with refs or state, and not always use the built-in batching behaviour.

Desktop (please complete the following information):

  • OS: macOS Mojave
  • Browser: Chrome
  • Version: 87.0.4280.141

Additional context

As a quick, very naive hack, I replaced the scheduleMicrotask function here:

https://github.com/tannerlinsley/react-query/blob/80cecef22c3e088d6cd9f8fbc5cd9e2c0aab962f/src/core/utils.ts#L362

with the following:

export function scheduleMicrotask(callback) {
	callback()
}

This substantially improved UI responsiveness in our case, dramatically improving timings by removing the batch update triggered from here:

https://github.com/tannerlinsley/react-query/blob/ac342e237ae9fab6759f2d7be616662da6c16225/src/core/notifyManager.ts#L68

I would like to request that batching either be opt-in or opt-out, either globally or maybe per query. I'd be perfectly happy with a global workaround if it provides a quicker resolution.

Edit: Forgot to mention I may be able to help with this depending on what the best course of action is!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions