xmlXPathEvalExpression - runtime increases quadratically with number of nodes in the document
I first reported this issue in Nokogiri, a Ruby XML library built on libxml2: https://github.com/sparklemotion/nokogiri/issues/1861
We have an HTML document of about 1.5MB - mostly HTML tables, which is being styled via premailer. Fundamentally, it inlines your styles by finding nodes in a document for which styles in a stylesheet apply. This is simple enough. However, we found that Nokogiri's xpath search (underlayed by libxml2) gets EXCEPTIONALLY slow for each search that contains classes or IDs when there are a significant number of nodes in your document.
Further investigation fingers libxml2 as the culprit, in particular xmlXPathNodeSetMergeAndClear:
There's a full repro case here: https://gist.github.com/flavorjones/1894c21e0bbc157b48a56f76233dffe7
I'm somewhat out of my depth with regards to libxml2, but this recently came back up and I realized I'd never reported it over here. Please let me know if there's further help I can provide to get this tracked down.