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
feat(builders): parallelize renders in prerender builder (#1396)
## Goal
Increase the performance of the prerender builder. I tested against 800 routes that each make a single http.get request and observed approximately a 5 times speedup.
## Child Process
We chose to fork child processes using the child_process API because:
We are not sure if these operations are thread safe
fork is used specifically to spawn new Node.js processes, which is our exact use case
Implementation
render.ts
This file is specifically designed to be called as a child process. It expects specific arguments to be passed and expects process.send to exist (which only happens when a parent process exists). The args that this file expects are:
indexHtml: The base html for rendering routes
serverBundlePath: The path to the server module bundle
browserOutputPath: The path to the browser builders output
allRoutes: The rest of the arguments passed are the routes to be rendered
index.ts
Calling _renderUniversal now forks child processes that run render.ts to render the routes in parallel.
There is an issue with forking processes within an angular builder where the parent process will exit before the child processes finish. This is likely because somewhere in our builder logic we call process.exit or something like that which kills the parent process early. To fix this issue, we wrap child processes in promises that resolve when the process finishes (either by exiting or erring).
## Tests
These changes completely break existing unit tests. Although helper functions such as getRange in render.ts can still be unit tested, integration tests should be what we really depend on. It might be worth it to move unit testable helper functions to a utils.ts file.
0 commit comments