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

Clear memoized for state while deferring notifications #261

Merged
merged 4 commits into from
Nov 6, 2024

Conversation

ShirShintel
Copy link
Contributor

In this PR, I added an option to clear memoizeForState cache on every state change, if deferring notifications.
This is done because we normally clear the memoizeForState` cache only when notifying subscribers, which does not happen while deferring notifications. This may cause incorrect results.

Currently this is done only when given an optional argument to deferSubscriberNotifications (which makes the code temporarily ugly), so we can verify that it does not cause performance issues. In the future we would like to do it by default.

src/throttledStore.tsx Outdated Show resolved Hide resolved
@@ -279,17 +280,19 @@ export const createThrottledStore = (
observableNotify: onObservableNotify,
resetPendingNotifications: resetAllPendingNotifications,
hasPendingSubscribers: () => pendingBroadcastNotification,
deferSubscriberNotifications: async action => {
deferSubscriberNotifications: async (action, shouldClearMemoizedForState) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest changing to parameter to be {shouldClearMemoizedForState} as options object to allow forward compatibility.
Also, it might be misleading, since it would clear cache only on dispatch, maybe we should name it shouldDispatchClearCache or something like that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wanted this to be a temporary solution, so that after we make sure it does not hurt performance, we'll remove this option and do it by default. In that case, do you still want an options object?

regarding the name - changed :)

@ShirShintel ShirShintel requested a review from itsh01 November 6, 2024 08:05
@ShirShintel ShirShintel merged commit af32f3c into master Nov 6, 2024
1 check passed
@ShirShintel ShirShintel deleted the clear-memo-in-defer branch November 6, 2024 09:18
@ShirShintel ShirShintel changed the title Clear memoized for state while deferirng notifications Clear memoized for state while deferring notifications Nov 6, 2024
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

Successfully merging this pull request may close these issues.

3 participants