You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
REXML::Node#each_recursive is a fundamental operation to traverse XML nodes. In particular, CSS selector uses this method heavily.
Unfortunately, this method is extremely slow. The following Gist contains a tiny (but mostly equivalent) each_recursive implementation and their benchmarks.
And, the below is a result of this script on my laptop (Apple M1 Pro, 14 inch, 32 GB) and Ruby 3.3.2.
$ ruby bench.rb user system total real each_recursive 2.421999 0.008742 2.430741 ( 2.453438)my_each_recursive 0.057647 0.000049 0.057696 ( 0.058718)
$ ruby --yjit bench.rb user system total real each_recursive 1.613353 0.008227 1.621580 ( 1.625374)my_each_recursive 0.025493 0.000124 0.025617 ( 0.025748)
Yes, REXML's each_recursive is ~50x (or ~80x with YJIT) slower than my tiny implementation.
I believe REXML does a lot of extra work, and we can make it faster.
The text was updated successfully, but these errors were encountered:
REXML::Node#each_recursive
is a fundamental operation to traverse XML nodes. In particular, CSS selector uses this method heavily.Unfortunately, this method is extremely slow. The following Gist contains a tiny (but mostly equivalent)
each_recursive
implementation and their benchmarks.https://gist.github.com/makenowjust/b4852a59e53f0c85c740818c75303d5e
And, the below is a result of this script on my laptop (Apple M1 Pro, 14 inch, 32 GB) and Ruby 3.3.2.
Yes, REXML's
each_recursive
is ~50x (or ~80x with YJIT) slower than my tiny implementation.I believe REXML does a lot of extra work, and we can make it faster.
The text was updated successfully, but these errors were encountered: