Skip to content

Lightpanda: the headless browser designed for AI and automation

perf(css): skip inline-style allocation for elements without inline styles

Adrià Arrufat41cb1bc176ae
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);
}