refactor: add concurrent promise pooling for render task #3366
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #3362
This PR provides a more efficient approach of limiting the concurrent promise memory usage by introducing a "Pool" model. Other than using "batches" of tasks (as implemented in #3285) which waits for all tasks to finish before dispatching next batch, this approach dispatches a new task upon the conclusion of any currently running task.
Currently the
thread count
is hard-coded as64
. I plan to make it available for user configuration later.Changes Made
Added an utility (pool.ts) to "src/node/utils/":
This utility provides a easy-to-use API of controlling the amount of microtasks dispatched to the JavaScript event loop.
In addition to its basic use case when you need multi-process pooling (like Python's
multiprocessing.Pool
), it can also optimize memory utilization by limiting the amount of local enclosures and garbage-collecting them as soon as possible.Refactored "src/node/build/build.ts":
Instead of using
Promise.all
from either the original code or Improved Build Efficiency for Large Blog with Batch Processing: Prevent Javascript heap out of memory #3285, I introduced the pooling mechanism enabled by the above mentioned utility.Future Improvements
max_threads
.Additional Comments
This is the first PR I've ever created. I would appreciate any comments on errors or mistakes I made in this PR.