mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
afe6abfc09
Given a selector like `.foo .bar #baz`, we know that elements with the class names `foo` and `bar` must be present in the ancestor chain of the candidate element, or the selector cannot match. By keeping track of the current ancestor chain during style computation, and which strings are used in tag names and attribute names, we can do a quick check before evaluating the selector itself, to see if all the required ancestors are present. The way this works: 1. CSS::Selector now has a cache of up to 8 strings that must be present in the ancestor chain of a matching element. Note that we actually store string *hashes*, not the strings themselves. 2. When Document performs a recursive style update, we now push and pop elements to the ancestor chain stack as they are entered and exited. 3. When entering/exiting an ancestor, StyleComputer collects all the relevant string hashes from that ancestor element and updates a counting bloom filter. 4. Before evaluating a selector, we first check if any of the hashes required by the selector are definitely missing from the ancestor filter. If so, it cannot be a match, and we reject it immediately. 5. Otherwise, we carry on and evaluate the selector as usual. I originally tried doing this with a HashMap, but we ended up losing a huge chunk of the time saved to HashMap instead. As it turns out, a simple counting bloom filter is way better at handling this. The cost is a flat 8KB per StyleComputer, and since it's a bloom filter, false positives are a thing. This is extremely efficient, and allows us to quickly reject the majority of selectors on many huge websites. Some example rejection rates: - https://amazon.com: 77% - https://github.com/SerenityOS/serenity: 61% - https://nytimes.com: 57% - https://store.steampowered.com: 55% - https://en.wikipedia.org: 45% - https://youtube.com: 32% - https://shopify.com: 25% This also yields a chunky 37% speedup on StyleBench. :^) |
||
---|---|---|
.. | ||
AudioBox.cpp | ||
AudioBox.h | ||
AvailableSpace.cpp | ||
AvailableSpace.h | ||
BlockContainer.cpp | ||
BlockContainer.h | ||
BlockFormattingContext.cpp | ||
BlockFormattingContext.h | ||
Box.cpp | ||
Box.h | ||
BoxModelMetrics.cpp | ||
BoxModelMetrics.h | ||
BreakNode.cpp | ||
BreakNode.h | ||
ButtonBox.cpp | ||
ButtonBox.h | ||
CanvasBox.cpp | ||
CanvasBox.h | ||
CheckBox.cpp | ||
CheckBox.h | ||
FlexFormattingContext.cpp | ||
FlexFormattingContext.h | ||
FormAssociatedLabelableNode.h | ||
FormattingContext.cpp | ||
FormattingContext.h | ||
FrameBox.cpp | ||
FrameBox.h | ||
GridFormattingContext.cpp | ||
GridFormattingContext.h | ||
ImageBox.cpp | ||
ImageBox.h | ||
ImageProvider.cpp | ||
ImageProvider.h | ||
InlineFormattingContext.cpp | ||
InlineFormattingContext.h | ||
InlineLevelIterator.cpp | ||
InlineLevelIterator.h | ||
InlineNode.cpp | ||
InlineNode.h | ||
Label.cpp | ||
Label.h | ||
LabelableNode.cpp | ||
LabelableNode.h | ||
LayoutState.cpp | ||
LayoutState.h | ||
LineBox.cpp | ||
LineBox.h | ||
LineBoxFragment.cpp | ||
LineBoxFragment.h | ||
LineBuilder.cpp | ||
LineBuilder.h | ||
ListItemBox.cpp | ||
ListItemBox.h | ||
ListItemMarkerBox.cpp | ||
ListItemMarkerBox.h | ||
Node.cpp | ||
Node.h | ||
RadioButton.cpp | ||
RadioButton.h | ||
ReplacedBox.cpp | ||
ReplacedBox.h | ||
SVGBox.cpp | ||
SVGBox.h | ||
SVGFormattingContext.cpp | ||
SVGFormattingContext.h | ||
SVGGeometryBox.cpp | ||
SVGGeometryBox.h | ||
SVGGraphicsBox.cpp | ||
SVGGraphicsBox.h | ||
SVGMaskBox.cpp | ||
SVGMaskBox.h | ||
SVGSVGBox.cpp | ||
SVGSVGBox.h | ||
SVGTextBox.cpp | ||
SVGTextBox.h | ||
SVGTextPathBox.cpp | ||
SVGTextPathBox.h | ||
TableFormattingContext.cpp | ||
TableFormattingContext.h | ||
TableGrid.cpp | ||
TableGrid.h | ||
TableWrapper.cpp | ||
TableWrapper.h | ||
TextNode.cpp | ||
TextNode.h | ||
TreeBuilder.cpp | ||
TreeBuilder.h | ||
VideoBox.cpp | ||
VideoBox.h | ||
Viewport.cpp | ||
Viewport.h |