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

Big performance issue #31

Open
magrinj opened this issue Sep 23, 2020 · 2 comments
Open

Big performance issue #31

magrinj opened this issue Sep 23, 2020 · 2 comments

Comments

@magrinj
Copy link

magrinj commented Sep 23, 2020

I was using this library to blacklist a part of my reducer state.
This lead in big performances issues, using a simple blacklist filter like this one:

export const blackListEntitiesFilter = createBlacklistFilter('entities', [
  'activities',
  'photos',
  'users',
]);

With this filter, app became really slow ! The amount of datas is equivalent to 33kb.

So I use this custom filter that is doing the same:

  createTransform(
    // inbound
    (inboundState, key) => {
      return inboundState
        ? omit(inboundState, ['activities', 'photos', 'users'])
        : inboundState;
    },

    // outbound
    (outboundState, key) => {
      return outboundState
        ? omit(outboundState, ['activities', 'photos', 'users'])
        : outboundState;
    },

    {whitelist: ['entities']},
  ),

And the app works well for now, maybe it's related to the cloneDeep of this library when the state grow.
This library should use pick and omit from lodash, as this two functions are working with path and avoid cloning state !

@andrekovac
Copy link

@magrinj Thanks for your solution!

Another solution without 3-rd party libraries (via the spread operator):

createTransform(
  // hydration (inbound)
  (inboundState, key) => {
    const { activities, photos, users, ...restOfInboundState } = inboundState;
    return restOfInboundState;
  },
  // rehydration (outbound)
  (outboundState, key) => {
    return { ...outboundState };
  },
  { whitelist: ['entities'] }
);

@chrisharrison
Copy link

Why would you return { ...outboundState } rather than just return outboundState?

@edy edy added the help wanted label Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants