From 41cb1bc176ae59b56f7e57fcaa0d158dfb107a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Tue, 30 Jun 2026 15:29:43 +0200 Subject: [PATCH] perf(css): skip inline-style allocation for elements without inline styles The visibility predicate called getInlineStyleProperty -> getOrCreateStyle, which always allocated a CSSStyleProperties + CSSStyleDeclaration and inserted into frame._element_styles, even for elements with no style= attribute. Every semantic-tree / interactiveElements walk checks visibility on every element, so this was one wasted allocation per element per walk on the agent's hot path. Only materialize the inline-style object when one already exists (JS-set styles) or the element actually carries a style= attribute; otherwise return null without allocating. --- src/browser/StyleManager.zig | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/browser/StyleManager.zig b/src/browser/StyleManager.zig index 79936e1d3..231de0e6f 100644 --- a/src/browser/StyleManager.zig +++ b/src/browser/StyleManager.zig @@ -864,9 +864,13 @@ const CheckVisibilityOptions = struct { const INLINE_PRIORITY: u64 = std.math.maxInt(u64); fn getInlineStyleProperty(el: *Element, property_name: String, frame: *Frame) ?*CSSStyleProperty { - const style = el.getOrCreateStyle(frame) catch |err| { - log.err(.browser, "StyleManager getOrCreateStyle", .{ .err = err }); - return null; + const style = frame._element_styles.get(el) orelse blk: { + // No JS-set style object and no style attribute -> nothing inline to read. + if (el.getAttributeSafe(comptime .wrap("style")) == null) return null; + break :blk el.getOrCreateStyle(frame) catch |err| { + log.err(.browser, "StyleManager getOrCreateStyle", .{ .err = err }); + return null; + }; }; return style.asCSSStyleDeclaration().findProperty(property_name); }