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

Optimize Memory Usage by Hoisting Function in For Loop 💽 #51242

Merged
merged 4 commits into from
Dec 23, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,14 @@ primordials.SafePromiseAllReturnVoid = (promises, mapFn) =>
new Promise((resolve, reject) => {
let pendingPromises = promises.length;
if (pendingPromises === 0) resolve();
const onPromiseSettled = () => {
sanjaiyan-dev marked this conversation as resolved.
Show resolved Hide resolved
if (--pendingPromises === 0) {
resolve();
}
};
for (let i = 0; i < promises.length; i++) {
const promise = mapFn != null ? mapFn(promises[i], i) : promises[i];
PromisePrototypeThen(PromiseResolve(promise), () => {
if (--pendingPromises === 0) resolve();
}, reject);
PromisePrototypeThen(PromiseResolve(promise), onPromiseSettled, reject);
sanjaiyan-dev marked this conversation as resolved.
Show resolved Hide resolved
}
});

Expand Down
Loading