Skip to content

performance.getEntriesByType returns entries out of order #42024

@nolanlawson

Description

@nolanlawson

Version

17.5.0

Platform

Linux 5.13.0-28-generic #31~20.04.1-Ubuntu SMP Wed Jan 19 14:08:10 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

perf_hooks

What steps will reproduce the bug?

Run this file (e.g. node index.js)

// index.js
(async () => {
  const sleep = ms => new Promise(resolve => setTimeout(() => resolve(), ms))

  performance.mark('one')
  await sleep(50)
  performance.mark('two')
  await sleep(50)
  performance.mark('three')
  await sleep(50)
  performance.measure('three', 'three')
  await sleep(50)
  performance.measure('two', 'two')
  await sleep(50)
  performance.measure('one', 'one')
  const entries = performance.getEntriesByType('measure')
  console.log(entries.map(x => x.name))
})()

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

Using the above code, it consistently reproduces for me. Perhaps in certain environments you may need a longer sleep time due to jitter.

What is the expected behavior?

If you run the same snippet in Chrome, Firefox, or Safari (e.g. in a DevTools Console on example.com), it will output:

['one', 'two', 'three']

According to MDN, getEntriesByType should return entries in order of startTime:

The items will be in chronological order based on the entries' startTime.

What do you see instead?

Node v16 and v17 will output:

[ 'three', 'two', 'one' ]

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    perf_hooksIssues and PRs related to the implementation of the Performance Timing API.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions