Skip to content

Optimize css matching

Matthias Clasen requested to merge matthiasc/css-matching-2 into master

Break the selector tree into many

Since we can only match one name, doing a hash by matcher name lets us quickly discard most initial selectors, and having much smaller trees.

We can apply the same idea for style classes, as well, by looking up a tree for each class.

Comparing the number of gtk_css_selector_match() calls while moving the pointer outside the window, I see:

Before: 65773 selector matches (12863 positive)

After: 32704 selector matches (12278 positive)

So this cuts the numer of selectors we need to check roughly in half, at the cost of a handful of hash table lookups.

Of course, we optimize away things that are somewhat cheap, so in absolute numbers, the reduction is somewhat less impressive. when wiggling the mouse in an out, gtk_css_selector_tree_match_all goes from 10.5% to 8.5% with this change.

Edited by Matthias Clasen

Merge request reports