User:Jdm/SlowCSSSelectors
https://developer.mozilla.org/en/Writing_Efficient_CSS
http://mxr.mozilla.org/mozilla-central/source/layout/style/nsCSSRuleProcessor.cpp
http://mxr.mozilla.org/mozilla-central/source/layout/style/nsCSSRuleProcessor.h
http://mxr.mozilla.org/mozilla-central/source/layout/style/StyleRule.h
http://mxr.mozilla.org/mozilla-central/source/layout/style/StyleRule.cpp
http://mxr.mozilla.org/mozilla-central/source/layout/style/nsNthIndexCache.cpp
http://mxr.mozilla.org/mozilla-central/source/layout/style/nsNthIndexCache.h
Functions like SelectorMatches show up in C++ profiles when CSS selector matching is being a problem. However, that is too low level - individual calls of SelectorMatches are fast, but the sheer volume of calls causes the problem. Instead, RuleHash is used to avoid even looking at most selectors.