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

Update parallel benchmarks (Promise + Compose) #395

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lundibundi
Copy link
Member

  • Don't create object every time in Promise resolve
  • Collect results in an array in Compose bench as it is dome
    in Promise.all

@lundibundi lundibundi self-assigned this Dec 5, 2018
@tshemsedinov
Copy link
Member

We need to use queueMicrotask for promisess too because new Promise(resolve => resolve(value)) don't queue microtasks, it returns resolved promise immediately. You can check this by following example:

const f = callback => queueMicrotask(() => callback(10));
f(res => {
  console.log(res);
});

const p = new Promise(resolve => resolve(10));
console.dir({ p });

Output will be:

{ p: Promise { 10 } }
(node:32587) ExperimentalWarning: queueMicrotask() is experimental.
10

If we add queueMicrotask to promise:

const f = callback => queueMicrotask(() => callback(10));
f(res => {
  console.log(res);
});

const p = new Promise(resolve => queueMicrotask(() => resolve(10)));
p.then(res => {
  console.dir({ res });
});

Output will be:

10
{ res: 10 }

Now two cases are equal priority, so if we swap calls results will swap too:

const f = callback => queueMicrotask(() => callback(10));
const p = new Promise(resolve => queueMicrotask(() => resolve(10)));

p.then(res => {
  console.dir({ res });
});

f(res => {
  console.log(res);
});

Output will be:

{ res: 10 }
10

* Don't create object every time in Promise resolve
* Collect results in an array in Compose bench as it is dome
  in Promise.all
@lundibundi
Copy link
Member Author

ping @tshemsedinov

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.

5 participants