mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-07-31 09:46:05 -04:00
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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user