From 96e23f78e8151ce2cc3f894c9dfd001865ac4c89 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Tue, 30 Jun 2026 12:50:50 +0800 Subject: [PATCH] perf: Skip CSSStyleProperty creation if there is no style attribute Was reviewing https://github.com/lightpanda-io/browser/pull/2836 and realized the StyleManager's getInlineStyleProperty could be optimized to avoid creating the CSSStyleProperties in the case where there's no style attribute. --- src/browser/StyleManager.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/browser/StyleManager.zig b/src/browser/StyleManager.zig index 79936e1d3..92d3a32e7 100644 --- a/src/browser/StyleManager.zig +++ b/src/browser/StyleManager.zig @@ -864,6 +864,10 @@ const CheckVisibilityOptions = struct { const INLINE_PRIORITY: u64 = std.math.maxInt(u64); fn getInlineStyleProperty(el: *Element, property_name: String, frame: *Frame) ?*CSSStyleProperty { + if (!el.hasAttributeSafe(comptime .wrap("style"))) { + // cheap guard to avoid creating the CSSStyleProperty if there is no style attribute + return null; + } const style = el.getOrCreateStyle(frame) catch |err| { log.err(.browser, "StyleManager getOrCreateStyle", .{ .err = err }); return null;