Archive for November, 2008

CSS optimizations in khtml

November 27, 2008

It’s been a while since my last blog post and a lot has happened. So let me summarize some nice things. After my GSOC with SVG for khtml I felt like I need to do something more real-life, so I chose CSS to play with.
It’s appeared that recently web pages became slower and bigger, with heavy style sheets, so it was time for us to change something.

here is the bunch of optimizations was made for khtml before kde 4.2 release:
1. use AtomicString for CSS values, this way we reduce memory usage (with shared strings between different selectors) and improve item comparison
2. pre-parse class attribute selectors and store it as AtomicStrings (faster class look up)
3. better selectors collecting (linear algorithm instead of O(M*N) complexity)
4. finally, smart selectors choosing for potential match based on element’s class attribute, id attribute, local name id, so we don’t have to go over all selectors for every single element

Anyway, what’s in that? probably, not everyone is interested in code itself, so here is the impact:
– improvement on synthetic benchmark based on css taken from facebook from ~1s originally to 20ms with current trunk
– up-to 4x less memory usage for selectors with AtomicString on some heavy sites, like youtube
– much smoother site loading (youtube, facebook, etc)
– even acid3 got faster