-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Auto batch enhancer #2621
Auto batch enhancer #2621
Conversation
|
||
const subscribe: typeof store.subscribe = (listener) => { | ||
const wrappedListener: typeof listener = () => notifying && listener() | ||
const unsubscribe = store.subscribe(wrappedListener) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still calls through to store.subscribe
so all the sanity checks there still apply. We only keep a Set
copy of the subscribers that were added successfully to also be able to notify them on our own.
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 81e6c1b:
|
✅ Deploy Preview for redux-starter-kit-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
7384e3d
to
e5af85d
Compare
Hmm. Initial thoughts:
We can talk more about this when you've got time, but for 1.9 my inclination is to focus on addressing the known perf issue with RTKQ loading large lists with the middleware approach I added, and maybe consider a larger discussion about batching for 2.0. |
From how I've interpreted the tests (I've played around with a few of them), there are now two categories of tests that are failing:
Yes, it's probably a "selective" version of redux-batched-subscribe - actions happen immediately, but in some cases a subscriber notification may be throttled.
Not "stop doing any" - an action without the "batching" meta tag will always immediately notify subscribers. The idea is quite similar to a "non-branching suspense": we have low-priority updates and immediately-flushing updates. (In the next sentence, you can exchange "rerender" with "notify subscribers", it just gets weird to type).
I'm really open to other "generic" approaches - but I'd love something that is transparent on the reducer/devtools/middleware side.
So far the implementation of
I want to avoid a situation where in the next version we'll have to go back and add a second approach that would maybe not have broken current behaviour in the first place - which will leave us with the choice to un-break the rejections by adding yet another mini-breaking change. Another option could be to add something like this (definitely doesn't have to be this approach, but my gut feeling tells me it's not possible on a reducer level) as an optional enhancer - we only have gotten very few performance complaints in the first place. Maybe it would be okay to ship something that is not on by default and tell people "you can also activate this enhancer". |
Ok, the low/high-pri thing sorta makes sense. Maybe going off into the weeds here, but could the I think I missed that this PR was trying to apply the batching behavior to That said, I'm still not convinced that the change to those I'll have to think about this one some more. Still not happy with the options of "add this by default and everyone pays for the bundle size" vs "don't add it by default, and RTKQ users need to know to add this to get better perf". |
Ironically, my proof of concept had been applied to almost all actions - except for the condition rejection, as that one did not accept a I've also experimented with the test you added for this case - the comparison numbers are comparisons to "nothing before", not to your variant. As you see, the number of subscription triggers goes down massively this way as well, probably with a similar performance impact. If you still have those measuring scenarios around that you did with the other solution - could you maybe play around with it a bit when you have time? |
9d81675
to
e3a3acf
Compare
e3a3acf
to
66a657a
Compare
@@ -85,6 +86,12 @@ function updateMutationSubstateIfExists( | |||
} | |||
|
|||
const initialState = {} as any | |||
const prepareAutoBatched = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought: We could actually export this helper.
Superseded by #2846 . |
Mostly for discussion:
This would be my alternative approach to #2599
Downside:
defaultEnhancers
Upsides:
api.endpoint.foo.matchRejected
etc.batch
with a similar result - or all batch-related code in general - for RTKQ users it would probably even mean less overall bundle size, not more.