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

PerformanceObserver callback always runs async #41259

Closed
erj826 opened this issue Dec 21, 2021 · 3 comments
Closed

PerformanceObserver callback always runs async #41259

erj826 opened this issue Dec 21, 2021 · 3 comments

Comments

@erj826
Copy link
Contributor

erj826 commented Dec 21, 2021

Version

v16.13.1

Platform

Darwin ALT02923 19.6.0 Darwin Kernel Version 19.6.0: Tue Oct 12 18:34:05 PDT 2021; root:xnu-6153.141.43~1/RELEASE_X86_64 x86_64

Subsystem

No response

What steps will reproduce the bug?

Run the perf_hooks code snippet documented here.

const {
  performance,
  PerformanceObserver
} = require('perf_hooks');

const obs = new PerformanceObserver((list, observer) => {
  // Called three times synchronously. `list` contains one item.
  console.log('hello, world');
});
obs.observe({ type: 'mark' });

for (let n = 0; n < 3; n++)
  performance.mark(`test${n}`);

The above snippet outputs hello, world once. In node.js versions <16 it will output hello, world three times. The observer callback is never being called synchronously as the comment states it should be.

How often does it reproduce? Is there a required condition?

Always for node 16 and greater.

What is the expected behavior?

The PerformanceObserver callback should be run for each performance.mark() call. The callback should be called synchronously and the list argument should contain one item on each call so long as the buffered option on the observe function is not set to true. As documented here.

What do you see instead?

The PerformanceObserver callback is only run once after execution of the script.

Additional information

No response

@erj826 erj826 changed the title PerformanceObserver.oberver always buffers output PerformanceObserver.oberver always runs async Dec 21, 2021
@erj826 erj826 changed the title PerformanceObserver.oberver always runs async PerformanceObserver callback always runs async Dec 21, 2021
@jasnell
Copy link
Member

jasnell commented Dec 21, 2021

That's a documentation bug. This was changed fairly recently where the observer runs async. The doc change was just missed.

@erj826
Copy link
Contributor Author

erj826 commented Dec 21, 2021

Thanks James, I'll open a pr to update the docs.

@erj826 erj826 closed this as completed Dec 21, 2021
nodejs-github-bot pushed a commit that referenced this issue Dec 27, 2021
PR-URL: #41262
Refs: #41259
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Harshitha K P <[email protected]>
targos pushed a commit that referenced this issue Jan 14, 2022
PR-URL: #41262
Refs: #41259
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Harshitha K P <[email protected]>
danielleadams pushed a commit that referenced this issue Jan 31, 2022
PR-URL: #41262
Refs: #41259
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Harshitha K P <[email protected]>
Linkgoron pushed a commit to Linkgoron/node that referenced this issue Jan 31, 2022
PR-URL: nodejs#41262
Refs: nodejs#41259
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Harshitha K P <[email protected]>
danielleadams pushed a commit that referenced this issue Feb 1, 2022
PR-URL: #41262
Refs: #41259
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Harshitha K P <[email protected]>
@kenrick95
Copy link
Contributor

Hi, may I check what is the PR that introduces this behavior change to PerformanceObserver? I couldn't pinpoint it from the changelog. Thanks

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

No branches or pull requests

3 participants