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

perf: don't use await inside loops #6617

Merged
merged 12 commits into from Jun 5, 2023
Merged

perf: don't use await inside loops #6617

merged 12 commits into from Jun 5, 2023

Conversation

zkochan
Copy link
Member

@zkochan zkochan commented May 31, 2023

No description provided.

@woss
Copy link
Contributor

woss commented May 31, 2023

out of curiosity, how big an impact this change had?

@zkochan
Copy link
Member Author

zkochan commented May 31, 2023

I did not check all the places it is used yet. But I don't think it will be a big impact.

@RexSkz
Copy link
Contributor

RexSkz commented Jun 1, 2023

The biggest impact might be the "order", for example:

const result1 = [];
for (const item of arr) {
  result1.push(await calculate(item));
}

const result2 = [];
await Promise.all(arr.map(async () => {
  result2.push(await calculate(item));
}));

The order of result1 will be the same as arr, but the order of result2 depends on how long each calculate costs.

@zkochan zkochan marked this pull request as ready for review June 5, 2023 00:03
@zkochan zkochan merged commit 4b97f1f into main Jun 5, 2023
12 of 13 checks passed
@zkochan zkochan deleted the no-await-in-loop branch June 5, 2023 09:12
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

Successfully merging this pull request may close these issues.

None yet

3 participants