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

refactor: add concurrent promise pooling for render task #3366

Merged
merged 4 commits into from Dec 26, 2023

Conversation

zhangyx1998
Copy link
Contributor

@zhangyx1998 zhangyx1998 commented Dec 20, 2023

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 as 64. 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

  • Provide user configuration for 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.

@brc-dd
Copy link
Member

brc-dd commented Dec 26, 2023

I've changed the implementation to directly use p-map instead of maintaining a pool implementation here. I've tested it locally both your Pool and pMap give similar performance (109s build time / 2.73GB peak memory usage).

@brc-dd brc-dd merged commit 6dac9a4 into vuejs:main Dec 26, 2023
7 checks passed
@sr2ds
Copy link
Contributor

sr2ds commented Dec 26, 2023

great job @zhangyx1998 , congrats!

@zhangyx1998
Copy link
Contributor Author

great job @zhangyx1998 , congrats!

Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Node crashes when building default theme - "JavaScript heap out of memory"
3 participants