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

Question - Selectors in workers #10

Open
hirviid opened this issue Apr 2, 2021 · 3 comments
Open

Question - Selectors in workers #10

hirviid opened this issue Apr 2, 2021 · 3 comments

Comments

@hirviid
Copy link

hirviid commented Apr 2, 2021

Hi!

Your library looks very interesting and promising for our use case. We're working on a very big planning application with a lot of data in a redux store.
The state is quite flat and we use selectors (with reduxjs/reselect) to combine several parts of the state to get different filtered and nested data structures optimized for rendering in React. These selectors are the most heavy part of the application.

Would it be possible to move these selectors to a webworker as well?
Would Redux useSelector be able to import the selector from the webworker?

@dai-shi
Copy link
Owner

dai-shi commented Apr 2, 2021

Would it be possible to move these selectors to a webworker as well?

I think so. I assume you mean to use those selectors in reducers.

Would Redux useSelector be able to import the selector from the webworker?

Hm, so you mean the selector functions you pass to useSelector are heavy?
In this case, it'd require quite a bit of refactoring: Do heavy computations in reducers / middleware in pure redux, and useSelector in react-redux should be lightweight. It's so-called de-normalization. Maybe not very typical in normal redux.

@hirviid
Copy link
Author

hirviid commented Apr 3, 2021

Thanks for the quick response!

Our state is normalized indeed. We have some heavy parts in the reducers, where a certain action needs to update several parts of the state. But the most heavy part is in the selectors though, where we combine and calculate data from the state before giving it to a component. So in our case I guess it would make sense to try to move the selectors to a web worker.

I will make a proof of concept. I'm also looking at https://github.com/HerbCaudill/react-redux-worker , it looks like the selectors you pass to useSelector run in the worker in that package.

You can close this question if you want, I'll come with an update later when I have time for the poc.

@dai-shi
Copy link
Owner

dai-shi commented Apr 3, 2021

Cool! Look forward to hearing updates.

Feel free to drop questions about impl / expected behavior.

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

No branches or pull requests

2 participants