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

Background thread pool rendering #315

Open
airhorns opened this issue Mar 29, 2022 · 0 comments
Open

Background thread pool rendering #315

airhorns opened this issue Mar 29, 2022 · 0 comments

Comments

@airhorns
Copy link
Collaborator

React SSR can be a pretty expensive blocking CPU operation for a node server, which is bad, because it blocks the whole main event loop for the process, interrupting any other work underway. We should add a mode to fastify-renderer that allows rendering in a background worker. It will still block that worker's event loop, but only that worker, leaving the main thread to do its thing.

I think the right level to do this at is just for the rendering, and not for the props gathering or any other bits of the request flow. The fastify route handler still needs access to the fastify plugins to gather the props for that page, and to do stuff like making database calls, caching, running authentication handlers, etc. So, I think the right point at which to do work in the background thread is after the props have been returned by the route hander, and before we start sending them into React land.

I imagine there will be some challenges getting vite to work ok in the background thread but I think it is worth investigating as the performance and stability of this is a big win.

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