-
-
Notifications
You must be signed in to change notification settings - Fork 905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] optimize CSS class queries #2135
Comments
OK, I wrote a C function and wired it into a benchmark for XPath, and the TL;DR is that it's about 2x as fast. Here's the result:
I'm going to clean it up and ship a PR. |
flavorjones
added a commit
that referenced
this issue
Dec 18, 2020
available as `nokogiri-builtin:css-class` Part of #2135
PR is at #2137, but so I can wrap this issue up, the "builtin" method is ~2x faster on CRuby, but almost ~2x slower on JRuby for reasons that completely escape me. Here are the benchmarks:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What problem are you trying to solve?
Currently (v1.10.10), Nokogiri turns the CSS query
.red
into the XPath query:which is doing a lot of string manipulation under the hood:
normalize-space
creates a new string buffer and assembles it one byte at a time, cleaning up whitespace along the way (xpath.c:xmlXPathNormalizeFunction
), then strdups that stringconcat
is pretty expensive, allocating new strings and repeatedly calling strlen and strdupIt occurs to me that we could probably optimize this by registering a C function that would search through the
class
attribute looking for a class name match without all of the associated string manipulation.Let's tentatively call that function
css-class
, and this would be the generated XPath:I think what I'd like to do is:
css-class
XPath function in C and benchmark itThe text was updated successfully, but these errors were encountered: