Praise

12 views
Skip to first unread message

pachl

unread,
Mar 4, 2011, 8:14:05 PM3/4/11
to nokogiri-talk
I just want to say thanks to the fine developers of Nokogiri.

I only use Xpath stuff in my integration tests. I've been using REXML
for years and have never tried an alternative. I've know that REXML
isn't the fasted thing around, but it has always worked for me, albeit
slow at times.

Well, last night I created a test that involves posting lots of
comments to a blog post. A single test that executes exactly (2)
simple Xpath queries took over 50 seconds! I seriously thought
something was wrong with my computer. I checked my CPU temp and
ensured speed step didn't kick in and crank my processor down.

Long story short, I just don't have 50 seconds to spare. I installed
Nokogiri and converted my tests to use Nokogiri. Now my test takes
0.18 seconds!!!!!

AMAZING!!!! You guys just saved me 49.82 seconds!

The CSS selectors look cool too. Now, I'll probably never use REXML
again. Cheers guys!

Clint

Hampton

unread,
Mar 5, 2011, 8:02:10 AM3/5/11
to nokogi...@googlegroups.com
Hear! Hear!


--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To post to this group, send email to nokogi...@googlegroups.com.
To unsubscribe from this group, send email to nokogiri-tal...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nokogiri-talk?hl=en.


David Kahn

unread,
Mar 5, 2011, 11:16:38 AM3/5/11
to nokogi...@googlegroups.com
On Fri, Mar 4, 2011 at 7:14 PM, pachl <clint...@gmail.com> wrote:
I just want to say thanks to the fine developers of Nokogiri.

I only use Xpath stuff in my integration tests. I've been using REXML
for years and have never tried an alternative. I've know that REXML
isn't the fasted thing around, but it has always worked for me, albeit
slow at times.

Well, last night I created a test that involves posting lots of
comments to a blog post. A single test that executes exactly (2)
simple Xpath queries took over 50 seconds! I seriously thought
something was wrong with my computer. I checked my CPU temp and
ensured speed step didn't kick in and crank my processor down.

Long story short, I just don't have 50 seconds to spare. I installed
Nokogiri and converted my tests to use Nokogiri. Now my test takes
0.18 seconds!!!!!

AMAZING!!!! You guys just saved me 49.82 seconds!

Yeah, I can second that, had similar or even greater time savings.... makes me wonder (albeit not enough to look into it) what REXML is doing all that time.
 

The CSS selectors look cool too. Now, I'll probably never use REXML
again. Cheers guys!

Clint

Aaron Patterson

unread,
Mar 5, 2011, 2:21:26 PM3/5/11
to nokogi...@googlegroups.com
On Sat, Mar 5, 2011 at 8:16 AM, David Kahn <d...@structuralartistry.com> wrote:
>
>
> On Fri, Mar 4, 2011 at 7:14 PM, pachl <clint...@gmail.com> wrote:
>>
>> I just want to say thanks to the fine developers of Nokogiri.
>>
>> I only use Xpath stuff in my integration tests. I've been using REXML
>> for years and have never tried an alternative. I've know that REXML
>> isn't the fasted thing around, but it has always worked for me, albeit
>> slow at times.
>>
>> Well, last night I created a test that involves posting lots of
>> comments to a blog post. A single test that executes exactly (2)
>> simple Xpath queries took over 50 seconds! I seriously thought
>> something was wrong with my computer. I checked my CPU temp and
>> ensured speed step didn't kick in and crank my processor down.
>>
>> Long story short, I just don't have 50 seconds to spare. I installed
>> Nokogiri and converted my tests to use Nokogiri. Now my test takes
>> 0.18 seconds!!!!!
>>
>> AMAZING!!!! You guys just saved me 49.82 seconds!
>
> Yeah, I can second that, had similar or even greater time savings.... makes
> me wonder (albeit not enough to look into it) what REXML is doing all that
> time.

There are a few costs you pay when using REXML. I'll list a few I can
think of off the top of my head:

1. String interning: libxml2 keeps a dictionary of strings which keeps
memory low. For example, if an attribute is named "foo", there is
only one copy of the "foo" string in memory. When someone in ruby
land requests the string, we copy it and provide a ruby object. This
is not true in REXML.

2. In REXML, Ruby objects are created for every node, whether you need
them or not. nokogiri is lazy about Ruby object creation. libxml2
builds a tree of nodes in memory. Nokogiri keeps a pointer to the
tree, but does not wrap any of the objects until someone in Ruby land
specifically requests that object.

3. Method calls on XPath traversal. REXML must call ruby methods when
traversing the document tree if someone makes an xpath query. libxml2
merely has to follow pointers.

There's more stuff, but I can't think of it now.

--
Aaron Patterson
http://tenderlovemaking.com/

pachl

unread,
Mar 5, 2011, 9:30:57 PM3/5/11
to nokogiri-talk
On Mar 5, 12:21 pm, Aaron Patterson <aaron.patter...@gmail.com> wrote:
>
> 3. Method calls on XPath traversal.  REXML must call ruby methods when
> traversing the document tree if someone makes an xpath query.  libxml2
> merely has to follow pointers.

Ah yes, following and de-referencing C/C++ pointers compared to
traversing Ruby objects is like night and day. In my uneducated
hypothesis (haven't looked at any of the library code), this is
probably the biggest factor.

I started to convert some other tests to Nokogiri; it's amazing how
much faster my test suite is running. Plus I've been using the CSS
selectors, which is much simpler. So far, the only place I found Xpath
to be a better tool is when I need to access TD tags within a table.
Nokogiri is cool because it gives me options! I'm very happy. :-)
Thanks devs!
Reply all
Reply to author
Forward
0 new messages