Skip to content

PerformanceObserver callback always runs async #41259

Closed
@erj826

Description

@erj826

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions