Skip to content

gc performance entries report incorrect startTime #43062

Closed
@amilajack

Description

@amilajack

Version

v17.9.0

Platform

Darwin Amilas-MacBook-Pro.local 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64 x86_64

Subsystem

No response

What steps will reproduce the bug?

All performance entries' startTime should be relative to performance.timeOrigin.

repro:

import { PerformanceObserver } from "perf_hooks";

const formatTime = (ms) => new Date(ms).toLocaleString();

console.log(`time origin: ${formatTime(performance.timeOrigin)}`);

// observe mark and gc entries
const observer = new PerformanceObserver((list) => {
  list.getEntries().forEach(({ entryType, startTime }) => {
    // gc performance entries aren't relative to timeOrigin
    console.log(entryType, formatTime(startTime + performance.timeOrigin));
  });
});
observer.observe({
  entryTypes: ["mark", "gc"],
});

// Mark entries are relative to timeOrigin
performance.mark("foo");

// Create some objects
setInterval(() => {
  const arr = new Array(1_000_000).fill(0);
  for (let i = 0; i < arr.length; i++) {
    arr[i] += 1;
  }
}, 1_000);

output:

time origin: 5/11/2022, 11:07:35 AM # correct
mark 5/11/2022, 11:07:35 AM            # correct
gc 5/20/2022, 10:23:36 AM              # incorrect
gc 5/20/2022, 10:23:36 AM              # incorrect
gc 5/20/2022, 10:23:37 AM              # incorrect
gc 5/20/2022, 10:23:38 AM              # incorrect
gc 5/20/2022, 10:23:39 AM              # incorrect

I've created a repl.it reproducing the bug.

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

I can reproduce it 100% of the time.

What is the expected behavior?

All performance entries' startTime should be relative to performance.timeOrigin. This isn't the case for the gc entry.

What do you see instead?

the startTime of gc performance entries are off by hours (see example output)

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions