Merge pull request #1638 from lightpanda-io/performance-mark-name

accept more performance mark name and return dummy 0
This commit is contained in:
Pierre Tachoire
2026-02-24 19:15:04 +01:00
committed by GitHub
2 changed files with 53 additions and 3 deletions

View File

@@ -252,6 +252,28 @@
} }
</script> </script>
<script id=measure_with_navigation_timing_marks>
{
// performance.measure() must accept PerformanceTiming attribute names
// (e.g. "fetchStart") as start/end marks per the W3C User Timing Level 2 spec.
// https://www.w3.org/TR/user-timing/#dom-performance-measure
performance.clearMarks();
performance.clearMeasures();
performance.mark("mark-dataComplete");
let m = performance.measure("dataComplete", "fetchStart", "mark-dataComplete");
testing.expectEqual('dataComplete', m.name);
testing.expectEqual('measure', m.entryType);
testing.expectEqual(true, m.duration >= 0);
// navigationStart is also a valid mark name (was already supported)
performance.mark("mark-end");
let m2 = performance.measure("fromNav", "navigationStart", "mark-end");
testing.expectEqual('fromNav', m2.name);
testing.expectEqual(true, m2.duration >= 0);
}
</script>
<script id=mixed_marks_and_measures> <script id=mixed_marks_and_measures>
{ {
performance.clearMarks(); performance.clearMarks();

View File

@@ -208,9 +208,37 @@ fn getMarkTime(self: *const Performance, mark_name: []const u8) !f64 {
} }
} }
// Recognized mark names by browsers. `navigationStart` is an equivalent // PerformanceTiming attribute names are valid start/end marks per the
// to 0. Others are dependant to request arrival, end of request etc. // W3C User Timing Level 2 spec. All are relative to navigationStart (= 0).
if (std.mem.eql(u8, "navigationStart", mark_name)) { // https://www.w3.org/TR/user-timing/#dom-performance-measure
//
// `navigationStart` is an equivalent to 0.
// Others are dependant to request arrival, end of request etc, but we
// return a dummy 0 value for now.
const navigation_timing_marks = std.StaticStringMap(void).initComptime(.{
.{ "navigationStart", {} },
.{ "unloadEventStart", {} },
.{ "unloadEventEnd", {} },
.{ "redirectStart", {} },
.{ "redirectEnd", {} },
.{ "fetchStart", {} },
.{ "domainLookupStart", {} },
.{ "domainLookupEnd", {} },
.{ "connectStart", {} },
.{ "connectEnd", {} },
.{ "secureConnectionStart", {} },
.{ "requestStart", {} },
.{ "responseStart", {} },
.{ "responseEnd", {} },
.{ "domLoading", {} },
.{ "domInteractive", {} },
.{ "domContentLoadedEventStart", {} },
.{ "domContentLoadedEventEnd", {} },
.{ "domComplete", {} },
.{ "loadEventStart", {} },
.{ "loadEventEnd", {} },
});
if (navigation_timing_marks.has(mark_name)) {
return 0; return 0;
} }