w3c / performance-timeline

Performance Timeline
https://w3c.github.io/performance-timeline/
Other
111 stars 27 forks source link

Clarify sort order for entries with equivalent startTime #67

Closed JosephPecoraro closed 7 years ago

JosephPecoraro commented 7 years ago

The spec says that entries in PerformanceObserverEntryList should be sorted by start time:

Given optional name and type string values this algorithm returns a PerformanceEntryList object that contains a list of PerformanceEntry objects, sorted in chronological order with respect to startTime.

However, many entries may contain equivalent startTime and implementations may differ on how these are sorted.

In this test:

function wait() {
    let now = performance.now();
    while (now === performance.now())
        continue;
}

let observer = new PerformanceObserver((list) => {
    for (let mark of list.getEntries())
        console.log(mark.name + " - " + mark.startTime);
});

observer.observe({entryTypes: ["mark", "measure"]});
performance.mark("mark1");
performance.measure("measure1");
wait(); // Ensure mark1 !== mark2 startTime by making sure performance.now advances.
performance.mark("mark2");
performance.measure("measure2");
performance.measure("measure-matching-mark2-1", "mark2");
wait(); // Ensure mark2 !== mark3 startTime by making sure performance.now advances.
performance.mark("mark3");
performance.measure("measure3");
performance.measure("measure-matching-mark2-2", "mark2");

With times: 0 < t1 < t2:


Implementations sort these differently:

Take just the top 3 in Chrome. It feels weird to have measure2 sorted after measure3 even though they have the same startTime.

JosephPecoraro commented 7 years ago

If the spec wants to clarify this, it can mention that PerformanceEntry creation time should be used when startTime is equivalent (effectively this is like "insertion order"). Otherwise the spec can be have a note that implementations may differ on the sort of equivalent startTime entries.

Either way, I can add a web-platform-test for sort.

toddreifsteck commented 7 years ago

Conclusion from the 2/8 W3C call: Keep the startTime ordering. Sites may depend on this. Add a note that entries with the same startTime have unspecified ordering.