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
Hi, I believe that selectors aren't memoized (per app state), though I'm not sure if this is an intended feature. I believe I'm using reductive in the normal manner, as follows:
I have a file called Selectors.re which has selectors defined like:
letselectUser= (state) => state.user;
I am using the same selector in multiple components using:
I tested memoization by adding a Js.Console.log in my selector and saw that it's called multiple times (I believe once per component that's rendered) without the state changing, then multiple times again every time the state changes.
So I tried memoizing my selectors with a cache with size=1:
/** * Memoize functions that depend on the appState. Works like memoize-one.*/letmemoize= (f: (appState => 'a)): (appState => 'a) => {
letlastState=ref(AppStore.initialState);letlastVal=ref(f(AppStore.initialState));
(state) => {
if (state === lastState^) {
//Js.Console.log("cache hit");
lastVal^;
} else {
//Js.Console.log("cache miss");
lastState := state;
lastVal := f(state);
lastVal^;
}
}
};letselectUser= memoize((state:appState) => state.user);
and now it correctly just runs the selectors once for each state update. I saw a React.useMemo2 in the code, so I thought a similar memoization was already implemented.
So unless I'm doing something wrong that's breaking memoization, getting this working would be an important performance improvement in this library!
The text was updated successfully, but these errors were encountered:
Hi, I believe that selectors aren't memoized (per app state), though I'm not sure if this is an intended feature. I believe I'm using reductive in the normal manner, as follows:
I have a file called Selectors.re which has selectors defined like:
I am using the same selector in multiple components using:
I tested memoization by adding a
Js.Console.log
in my selector and saw that it's called multiple times (I believe once per component that's rendered) without the state changing, then multiple times again every time the state changes.So I tried memoizing my selectors with a cache with size=1:
and now it correctly just runs the selectors once for each state update. I saw a
React.useMemo2
in the code, so I thought a similar memoization was already implemented.So unless I'm doing something wrong that's breaking memoization, getting this working would be an important performance improvement in this library!
The text was updated successfully, but these errors were encountered: