# \[FYI| Pure Java Nokogiri 1.5.0.beta.4

**URL:** <https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386>\
**Category:** JRuby\
**Created:** [January 28, 2011, 2:56am UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386 "2011-01-28T02:56:46Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 28, 2011, 2:56am UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386/1 "2011-01-28T02:56:46Z")

</div>

For those who are struggling to get pure Java Nokogiri work:

Pure Java Nokogiri 1.5.0.beta.4 is out. This version fixed the problem  
of not working on rack based environment. Also, other reported bugs  
were fixed. Please give it a try. I’m looking forward to having  
feedback from you.

-Yoko

---

<div class="post-metadata">

**Author:** ![Yoko\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@Yoko\_H](https://www.ruby-forum.com/u/Yoko_H)\
**Post date:** [January 28, 2011, 10:10am UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386/2 "2011-01-28T10:10:32Z")

</div>

Glad to see pure java nokogiri advancing.

Have you looked at performance anything? The main reason I cannot use  
it currently is performance.

For my small test (that I’m happy to send to you) I get the following  
in jruby with nokogiri

: [erik@zyrgelkwyt3]$ ; jruby footest-perf.rb  
Took 5797 ms

With none-java nokogiri I get

: [erik@zyrgelkwyt3]$ ; jruby footest-perf.rb  
Took 2648 ms

Somewhat unrelated, in this example jruby is way slower then mri ruby

: [erik@zyrgelkwyt3]$ ; /usr/local/bin/ruby footest-perf.rb  
Took 178 ms

Regards,  
Erik

---

<div class="post-metadata">

**Author:** ![Yoko\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@Yoko\_H](https://www.ruby-forum.com/u/Yoko_H)\
**Post date:** [January 28, 2011, 3:08pm UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386/3 "2011-01-28T15:08:36Z")

</div>

On Fri, Jan 28, 2011 at 3:10 AM, Erik B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> With none-java nokogiri I get
> 
> : [erik@zyrgelkwyt3]$ ; jruby footest-perf.rb  
> Took 2648 ms
> 
> Somewhat unrelated, in this example jruby is way slower then mri ruby
> 
> : [erik@zyrgelkwyt3]$ ; /usr/local/bin/ruby footest-perf.rb  
> Took 178 ms

Is this test available? One user had commented that the Java adapter  
was quite a bit faster for what they were doing.

-Tom

–  
blog: [http://blog.enebo.com](http://blog.enebo.com) twitter: tom\_enebo  
mail: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Yoko\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@Yoko\_H](https://www.ruby-forum.com/u/Yoko_H)\
**Post date:** [January 28, 2011, 6:46pm UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386/4 "2011-01-28T18:46:01Z")

</div>

On 28 janv. 2011, at 15:07, Thomas E Enebo wrote:

> Is this test available? One user had commented that the Java adapter  
> was quite a bit faster for what they were doing.

That might be me 🙂

I did tweet about some _massive_ speed improvements when switching from  
FFI based nokogiri to the Java based one in my specific case which  
involves _stream parsing_. In this case it basically means removing the  
shitload of boundary crossings caused by the parsing callbacks which the  
FFI layer overhead makes _painfully_ slow. The speedup is substantial in  
this case. And when I say substantial I mean between 50x and 100x faster  
depending on the dataset size.

I have a few issue with API incompatibilities but other than that  
Nokogiri Java is a godsend for me.

–  
Luc H. - [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Yoko\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@Yoko\_H](https://www.ruby-forum.com/u/Yoko_H)\
**Post date:** [January 31, 2011, 9:44pm UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386/5 "2011-01-31T21:44:21Z")

</div>

On Fri, Jan 28, 2011 at 12:45 PM, Luc H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On 28 janv. 2011, at 15:07, Thomas E Enebo wrote:
> 
> > Is this test available? One user had commented that the Java adapter  
> > was quite a bit faster for what they were doing.
> 
> That might be me 🙂
> 
> I did tweet about some _massive_ speed improvements when switching from FFI  
> based nokogiri to the Java based one in my specific case which involves _stream  
> parsing_. In this case it basically means removing the shitload of boundary  
> crossings caused by the parsing callbacks which the FFI layer overhead makes  
> _painfully_ slow. The speedup is substantial in this case. And when I say  
> substantial I mean between 50x and 100x faster depending on the dataset size.

Thanks for reporting your case. That’s awesome!

> I have a few issue with API incompatibilities but other than that Nokogiri Java  
> is a godsend for me.

There are tools to test “semantic equality of the document structure.”

> **[GitHub - flavorjones/lorax: XML/HTML diff generator, based on Nokogiri.](https://github.com/flavorjones/lorax)**
>
> XML/HTML diff generator, based on Nokogiri.

> **[GitHub - postmodern/nokogiri-diff: Calculate the differences between two XML/HTML...](https://github.com/postmodern/nokogiri-diff)**
>
> Calculate the differences between two XML/HTML documents.

(see the discussion  
[http://groups.google.com/group/nokogiri-talk/browse\_thread/thread/a16e0554158965ea?hl=en](http://groups.google.com/group/nokogiri-talk/browse_thread/thread/a16e0554158965ea?hl=en))

These might help you?

-Yoko

---

<div class="post-metadata">

**Author:** ![Yoko\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@Yoko\_H](https://www.ruby-forum.com/u/Yoko_H)\
**Post date:** [February 1, 2011, 7:51am UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386/6 "2011-02-01T07:51:20Z")

</div>

Yes. I can sent you the test later. Just need to look through it first.

Sent from my iPad

---

<div class="post-metadata">

**Author:** ![Yoko\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@Yoko\_H](https://www.ruby-forum.com/u/Yoko_H)\
**Post date:** [January 31, 2011, 9:33pm UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386/7 "2011-01-31T21:33:04Z")

</div>

Hi,

On Fri, Jan 28, 2011 at 4:10 AM, Erik B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> With none-java nokogiri I get
> 
> : [erik@zyrgelkwyt3]$ ; jruby footest-perf.rb  
> Took 2648 ms

As you pointed out pure Java version is slower than CRuby version.  
I’ve attempted various possible ways to improve performance, but  
there’s a limit. However, performance of pure Java version is expected  
to improve applying JVM or JIT options. So, would you give us the code  
used to measure the performance as Tom said?

-Yoko

---

<div class="post-metadata">

**Author:** ![Yoko\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@Yoko\_H](https://www.ruby-forum.com/u/Yoko_H)\
**Post date:** [February 10, 2011, 12:27pm UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386/8 "2011-02-10T12:27:43Z")

</div>

On Fri, Jan 28, 2011 at 2:56 AM, Yoko H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> For those who are struggling to get pure Java Nokogiri work:
> 
> Pure Java Nokogiri 1.5.0.beta.4 is out. This version fixed the problem  
> of not working on rack based environment. Also, other reported bugs  
> were fixed. Please give it a try. I’m looking forward to having  
> feedback from you.

Hi Yoko,

it seems 1.5.0.beta.4 does not validate xml versus xsd anymore…

I’ve a case where a xsd type is actually defined in another xsd file  
(header.xsd included), and it does not work anymore.

I can provide test cases separately… Meanwhile I reverted back to  
1.5.0.beta.3

–  
Christian

---

<div class="post-metadata">

**Author:** ![Yoko\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@Yoko\_H](https://www.ruby-forum.com/u/Yoko_H)\
**Post date:** [February 10, 2011, 8:42pm UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386/9 "2011-02-10T20:42:50Z")

</div>

Hello,  
Thank you for using pure Java Nokogiri!

On Thu, Feb 10, 2011 at 6:27 AM, Christian MICHON  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> it seems 1.5.0.beta.4 does not validate xml versus xsd anymore…
> 
> I’ve a case where a xsd type is actually defined in another xsd file  
> (header.xsd included), and it does not work anymore.
> 
> I can provide test cases separately… Meanwhile I reverted back to 1.5.0.beta.3

I changed the way of getting schema specified by schemaLocation upon  
the bug report. That bug was fixed. But, the fix seems to break  
another case.

I filed this issue,  
[https://github.com/tenderlove/nokogiri/issues/issue/417](https://github.com/tenderlove/nokogiri/issues/issue/417)

-Yoko

---

<div class="post-metadata">

**Author:** ![Yoko\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@Yoko\_H](https://www.ruby-forum.com/u/Yoko_H)\
**Post date:** [February 14, 2011, 3:08am UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386/10 "2011-02-14T03:08:54Z")

</div>

> Pure Java Nokogiri 1.5.0.beta.4 is out. This version fixed the problem  
> of not working on rack based environment.

I’m not familiar with this problem. Is there some information  
available about this?

I’m switching a parsing function in a JRuby on Rails app from REXML to  
Nokogiri. It parses an XML file and runs a few XPaths against it. I  
ran a benchmark comparing the two, and for good measure I ran it again  
using 1.5.0.beta.4.

Times below are for 1000 iterations, after warm-up:

#-----------------------------------------------------

# JRuby 1.6.0RC2 + nokogiri-1.4.4.2-java

# 

```
            user system total real

```

Nokogiri 6.503000 0.000000 6.503000 ( 6.503000)  
REXML 36.334000 0.000000 36.334000 ( 36.334000)

#-----------------------------------------------------

# JRuby 1.6.0RC2 + nokogiri-1.5.0.beta.4-java

# 

```
            user system total real

```

Nokogiri 24.952000 0.000000 24.952000 ( 24.952000)  
REXML 35.646000 0.000000 35.646000 ( 35.646000)

---

<div class="post-metadata">

**Author:** ![Yoko\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@Yoko\_H](https://www.ruby-forum.com/u/Yoko_H)\
**Post date:** [March 31, 2011, 1:32am UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386/11 "2011-03-31T01:32:03Z")

</div>

Erik,

Thanks for sharing the sample code and data.  
After beta.4 was released, I’ve tried various (possible) performance  
improvements. Now, current master branch became a little bit better  
though it’s still slow compared to FFI/C versions, especially for  
parsing a large xml document. For example, JRuby 1.6.0 on my MacBook,  
the result was below:

- Nokogiri beta.4

$ jruby footest-perf.rb  
Took 7924 ms

- master branch

$ jruby footest-perf.rb  
Took 7300 ms

I tried various JRuby and JVM options, too. Among them, a combination  
of jruby.compile.mode=FORCE and -server worked for me.

$ jruby -J-server -J-Djruby.compile.mode=FORCE footest-perf.rb  
Took 6780 ms

Including default settings of JRuby, the options given to the process  
were:

-Xserver -Djruby.memory.max=500m -Djruby.stack.max=2048k -Xmx500m  
-Xss2048k  
-Djffi.boot.library.path=/Users/yoko/Tools/jruby-1.6.0/lib/native/Darwin  
-Djruby.compile.mode=FORCE -Dfile.encoding=UTF-8  
-Xbootclasspath/a:/Users/yoko/Tools/jruby-1.6.0/lib/jruby.jar  
-Djruby.home=/Users/yoko/Tools/jruby-1.6.0  
-Djruby.lib=/Users/yoko/Tools/jruby-1.6.0/lib -Djruby.script=jruby  
-Djruby.shell=/bin/sh

As far as I watched the process over jconsole, memory usage was not  
the factor of slowness. The process used less than 150m of heap. From  
the result of -Xprof (JVM) and --profile (JRuby),  
[gist:895486 · GitHub](https://gist.github.com/895486), the biggest reason of the slowness  
seems to come from creating DOM tree by Xerces. However, I can’t  
replace XML parser at this moment. That will be a huge change and need  
a lot of work. So, you’d better use C version of Nokogiri when you  
parse large xml files.

Sorry, I can’t help so much ☹  
-Yoko

---

<div class="post-metadata">

**Author:** ![Yoko\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@Yoko\_H](https://www.ruby-forum.com/u/Yoko_H)\
**Post date:** [February 16, 2011, 8:33am UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386/12 "2011-02-16T08:33:15Z")

</div>

On Fri, Jan 28, 2011 at 3:07 PM, Thomas E Enebo [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > Took 5797 ms
> 
> Is this test available? One user had commented that the Java adapter  
> was quite a bit faster for what they were doing.

Attached are the tests I was using. It’s running roxml for mapping,  
which in turn is using nokogiri.

Current performance.

: [erik@zyrgelkwyt3]$ ; rvm use 1.8.7  
: [erik@zyrgelkwyt3]$ ; ruby -I. footest-perf.rb  
Took 258 ms

: [erik@zyrgelkwyt3]$ ; rvm use 1.9.2  
: [erik@zyrgelkwyt3]$ ; ruby -I. footest-perf.rb  
Took 185 ms

: [erik@zyrgelkwyt3]$ ; rvm jruby-1.6.0.RC2@global  
: [erik@zyrgelkwyt3]$ ; ruby -I. footest-perf.rb  
Took 6042 ms

: [erik@zyrgelkwyt3]$ ; rvm jruby-1.6.0.RC2@nokogiri-ffi  
: [erik@zyrgelkwyt3]$ ; ruby -I. footest-perf.rb  
Took 2616 ms

/Erik

---

<div class="post-metadata">

**Author:** ![Yoko\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@Yoko\_H](https://www.ruby-forum.com/u/Yoko_H)\
**Post date:** [March 31, 2011, 1:59am UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386/13 "2011-03-31T01:59:11Z")

</div>

> As far as I watched the process over jconsole, memory usage was not  
> the factor of slowness. The process used less than 150m of heap. From  
> the result of -Xprof (JVM) and --profile (JRuby),  
> [gist:895486 · GitHub](https://gist.github.com/895486), the biggest reason of the slowness  
> seems to come from creating DOM tree by Xerces. However, I can’t  
> replace XML parser at this moment. That will be a huge change and need  
> a lot of work. So, you’d better use C version of Nokogiri when you  
> parse large xml files.  
> Yoko, have you evaluated what xml parser would be a good fit for  
> replacing xerces? I know it would involve hard work, but if xerces is  
> the culprit I don’t see better options than start organizing the effort  
> ☹

Douglas Campos (qmx)  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> **[Home](https://random.qmx.me/)**
>
> thoughts by Doug Campos

---

<div class="post-metadata">

**Author:** ![Yoko\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/2bfe46/32.png) [@Yoko\_H](https://www.ruby-forum.com/u/Yoko_H)\
**Post date:** [March 31, 2011, 2:37am UTC](https://www.ruby-forum.com/t/fyi-pure-java-nokogiri-1-5-0-beta-4/202386/14 "2011-03-31T02:37:25Z")

</div>

On Wed, Mar 30, 2011 at 7:58 PM, Douglas Campos (qmx) [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > As far as I watched the process over jconsole, memory usage was not  
> > the factor of slowness. The process used less than 150m of heap. From  
> > the result of -Xprof (JVM) and --profile (JRuby),  
> > [gist:895486 · GitHub](https://gist.github.com/895486), the biggest reason of the slowness  
> > seems to come from creating DOM tree by Xerces. However, I can’t  
> > replace XML parser at this moment. That will be a huge change and need  
> > a lot of work. So, you’d better use C version of Nokogiri when you  
> > parse large xml files.  
> > Yoko, have you evaluated what xml parser would be a good fit for replacing  
> > xerces? I know it would involve hard work, but if xerces is the culprit I don’t  
> > see better options than start organizing the effort ☹

I have just looked at what parsers could cover what features of  
Nokogiri. Not just that. Software license is the matter, too. So far,  
no replacement of Xerces.

-Yoko
