Skip to content

Conversation

@nikneym
Copy link
Contributor

@nikneym nikneym commented Dec 19, 2025

This PR implements PerformanceObserver for mark and measure performance types. I'll add tests also but would like to receive reviews before that.

@nikneym nikneym changed the title Support PerformanceObserver Support PerformanceObserver API Dec 19, 2025
@nikneym nikneym marked this pull request as ready for review December 22, 2025 13:21
@nikneym nikneym added the zigdom label Dec 22, 2025
@nikneym nikneym requested a review from karlseguin December 22, 2025 13:21
Heavily based on MutationObserver and IntersectionObserver.
This still needs investigation. Spec doesn't refer usage of microtask queue for this, yet the current behavior doesn't match to Firefox and Chrome.
@nikneym nikneym force-pushed the nikneym/performance-observer branch from 459cef0 to e1ba5df Compare December 22, 2025 13:58
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem like this file is used anywhere in this PR?

const ShadowRoot = @import("webapi/ShadowRoot.zig");
const Performance = @import("webapi/Performance.zig");
const Screen = @import("webapi/Screen.zig");
const HtmlScript = @import("webapi/Element.zig").Html.Script;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used? (Can always use Element.Html.Script)

struct {
fn run(_page: *anyopaque) anyerror!?u32 {
const page: *Page = @ptrCast(@alignCast(_page));
page._performance_delivery_scheduled = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be set to false?

/// This doesn't emit callbacks but rather fills the queues of observers.
pub fn notifyPerformanceObservers(self: *Page, entry: *Performance.Entry) !void {
for (self._performance_observers.items) |observer| {
if (observer.interested(entry)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might encapsulate this in the observer, so just:

observer.newEntry(entry)

and let it decide how/if to handle it.

page._performance_delivery_scheduled = true;
// Dispatch performance observer events.
for (page._performance_observers.items) |observer| {
if (observer.hasRecords()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, maybe just call observer.dispatch() and let it deal with what (if anything) to do.

pub const prototype_chain = bridge.prototypeChain();
pub var class_id: bridge.ClassId = undefined;

pub const getEntries = bridge.function(EntryList.getEntries, .{});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be defined in JsApi, not Meta. This tells me there might be some tests missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants