You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which @ngrx/* package(s) are relevant/related to the feature request?
store
Information
createSelector uses a memoization function under the hood that stores the reference to the last argument (state object). This works great in a browser, where there is a single global NgRx state per app.
On the server (server rendering with Angular Universal), we get a new instance of the store, and a new instance of the global state for each user request.
It has two implications
Memoization is less efficient in SSR, when multiple requests are handled in parallel that use the same selector. All those requests keep overriding the stored last argument in the selector, effectively invalidating it every time.
After a request is finished, the memoized selector keeps the reference to the last State instance in the closure. It prevents this state instance from being garbage collected. In its extreme, we can end up in the situation where each selector stores a ref to a different State - having as many not GC'd State instances as we have selectors.
This feature request is primarily concerned with the second item - multiple state instances that are not GC'd between the requests.
The suggested solution would involve using weak refs to store the last argument of a memoized selector.
Furthermore, with weak refs we could store more that one last argument in the cache (via WeakMap) - thus also addressing my first bullet point from the above (should be careful with selectors args that are primitives though).
Describe any alternatives/workarounds you're currently using
None so far.
Theoretically, we could use createSelectorFactory (with a typing workaround because of #3987). But it means we need to update all selectors across the app. There is no way to override the default memoize function globally in the app.
I would be willing to submit a PR to fix this issue
Yes
No
The text was updated successfully, but these errors were encountered:
Which @ngrx/* package(s) are relevant/related to the feature request?
store
Information
createSelector
uses a memoization function under the hood that stores the reference to the last argument (state object). This works great in a browser, where there is a single global NgRx state per app.On the server (server rendering with Angular Universal), we get a new instance of the store, and a new instance of the global state for each user request.
It has two implications
This feature request is primarily concerned with the second item - multiple state instances that are not GC'd between the requests.
The suggested solution would involve using weak refs to store the last argument of a memoized selector.
Furthermore, with weak refs we could store more that one last argument in the cache (via WeakMap) - thus also addressing my first bullet point from the above (should be careful with selectors args that are primitives though).
Describe any alternatives/workarounds you're currently using
None so far.
Theoretically, we could use
createSelectorFactory
(with a typing workaround because of #3987). But it means we need to update all selectors across the app. There is no way to override the default memoize function globally in the app.I would be willing to submit a PR to fix this issue
The text was updated successfully, but these errors were encountered: