Performance of CSS Selectors Is Irrelevant
Post from March 12, 2009 (↻ November 29, 2017), filed under Web Development.
This and many other posts are also available as a pretty, well-behaved e-book: On Web Development.
…if you like to have a strict read of Steve Souders’ recent research. We’ve still got few but now a few more numbers backing up what we always suspected, that merely optimizing selectors is micro-optimization, micro-optimization that may shave off mere microseconds when avoiding the universal selector.
I welcome everyone interested in CSS development and performance to read Steve’s article, have a close, absorbing look at the following chart, and to memorize what follows after:
Figure: Page render time and number of CSS rules. (Copyright 2009 Steve Souders.)
Be very sure what to sacrifice code efficiency, maintainability, and understandability for. You already, absolutely know why performance is important, yet you also know what else matters. Focusing on selectors means saving at the wrong end.
About the Author
Jens Oliver Meiert is a technical lead and author (sum.cumo, W3C, O’Reilly). He loves trying things, including in the realms of philosophy, art, and adventure. Here on meiert.com he shares and generalizes and exaggerates some of his thoughts and experiences.
If you have any thoughts or questions (or recommendations) about what he writes, leave a comment or a message.
I think that CSS Micro optimization is very interesting subject. Yes probably “performance gains from optimizing CSS selectors will be small, and are not worth the costs”, but if we know what is better and faster in the first place, we should be able to write better(faster) CSS code. Little more research on this subject won’t heart.
Writing code with this kind of optimization in the first place is call “premature optimization” by software developers. Write code that is easy to read and does what it should with as few bugs as possible. If it has performance problems, search for the hot spots. Doing optimizations beforehand will make your code less maintainable.
Of cause nobody tries to write bad code. But after reading Steve Souders’ post it seems that the performance of css selectors is totally irrelevant in real life.