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

Revisit batching of updates with useOnyx #571

Open
hannojg opened this issue Jul 22, 2024 · 1 comment
Open

Revisit batching of updates with useOnyx #571

hannojg opened this issue Jul 22, 2024 · 1 comment

Comments

@hannojg
Copy link
Contributor

hannojg commented Jul 22, 2024

In this PR:

We added support for batching updates, so that react only has to commit one big update, instead of updating every component separately. Back then there were only two subscription mechanisms:

  • Onyx.connect
  • withOnyx

Right now, we only batch updates for withOnyx. The reason for that is that in the NewDot code we have a lot of places that do Onyx.connect outside of react and immediately expect data. So we only wanted to batch withOnyx updates, as these were only used with react:

function scheduleSubscriberUpdate<TKey extends OnyxKey>(
key: TKey,
value: OnyxValue<TKey>,
previousValue: OnyxValue<TKey>,
canUpdateSubscriber: (subscriber?: Mapping<OnyxKey>) => boolean = () => true,
): Promise<void> {
const promise = Promise.resolve().then(() => keyChanged(key, value, previousValue, canUpdateSubscriber, true, false));
batchUpdates(() => keyChanged(key, value, previousValue, canUpdateSubscriber, false, true));
return Promise.all([maybeFlushBatchUpdates(), promise]).then(() => undefined);
}

Now we have useOnyx, which internally uses Onyx.connect, not withOnyx. So all components using useOnyx might not be batched.

I opened this issue because I want to look closer, if we need to enable a certain batching logic when using the useOnyx hook.

@hannojg
Copy link
Contributor Author

hannojg commented Jul 22, 2024

Additionally, in fabric, react updates get batched automatically (if concurrent rendering is enabled) - so we might want to see if we can completely get rid of this manual batching mechanism.

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