Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Alternative XML parsers support in ActiveSupport for ActiveResource

#2084

The XMLmini implementation now switches between a LibXML or REXML implementation, depending on weather the LibXML library is available. As the implementation of the XMLmini is now separated out, it is very easy to implement Nokogiri or JREXML. The speed increase is quite stunning (up to 10 times as fast, probably more for large XML files).

It falls back to the old ruby implementation (REXML) if no other parsers are available.

Reported by Bart ten Brinke · February 26th, 2009 @ 09:59 AM

State: resolved
Milestone: none
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. José Valim
    José Valim

    Really great! +1 Just noticed that the patch file contains two patches:

    [PATCH] Added deflate, gzip support to active resource

    And:

    [PATCH] xml mini libxml support

    I think you want to send just the second one!

    Cheers!

    February 26th, 2009 @ 12:42 PM

  2. Alex Coles
  3. Bart ten Brinke
    Bart ten Brinke

    Sorry, squashed the correct tickets into a new diff.

    February 26th, 2009 @ 01:26 PM

  4. Willem van Bergen
    Willem van Bergen

    +1, this would be really helpful for our API needs as well.

    February 26th, 2009 @ 01:30 PM

  5. Michael Koziarski
    Michael Koziarski
    • Tag changed from activeresource, activesupport, patch, xml to activeresource, activesupport, patch, verified, xml

    I'd be nice to be able to choose between the different parsers rather than just relying on the presence of libxml, though that'd be a sensible default.

    Also, the new non-derivative work code (your changes) shouldn't have the copyright header as they can safely be MIT licensed.

    March 2nd, 2009 @ 05:49 AM

  6. Michael Koziarski
    Michael Koziarski

    Also, how would you suggest the jruby guys could plug in an alternative implementation with this patch? Could be a good thought experiment to make sure the modularity works.

    March 2nd, 2009 @ 05:49 AM

  7. Bart ten Brinke
    Bart ten Brinke

    Well, the selection code currently is located in the XMLmini Module. You could easily have a fall through there, but I could also set something up like a hook. Which would you prefer?

    March 3rd, 2009 @ 09:08 PM

  8. Bart ten Brinke
    Bart ten Brinke

    Let me rephrase that, as editing my comment seems to be impossible. This should be viewed as the base for alternative XML to hash parser implementations. XMLMini will be the front end and all alternative parsers should just implement ActiveSupport::XmlMini.parse

    In the future alternative parsers can be added to Rails core (and placed in the xml_mini sub folder). XMLmini can then implement a fall through that will decide which implementation is available.

    In the mean time people can write their own mixin in config/initializers that implements XmlMini.parse. The JRuby/Nokogiri people can either do the mix in on require or have a special function like Nokogiri.enable_active_resource.

    If you have a better suggestion to do this, please post it or post an example.

    You are right about the licenses. I have attached a new diff in which they are removed.

    March 3rd, 2009 @ 10:49 PM

  9. Repository
    Repository
    • State changed from new to committed

    (from [822c41d69d9228c9912d29ac45155d3a16bb5c50]) XmlMini supports different backend parsers, starting with libxml

    [#2084 Alternative XML parsers support in ActiveSupport for ActiveResource state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...

    March 8th, 2009 @ 08:42 PM

  10. Michael Koziarski
    Michael Koziarski
    • State changed from committed to open
    • Milestone cleared.

    I'm seeing lots of failures now with:

    
    test_serialization_of_nested_resource(FormatTest):
    NoMethodError: undefined method `default_keep_blanks=' for XML:Module
    

    Do we need an additional check on the version of libxml that's installed? This is with a stock ruby install from 10.5.6

    March 9th, 2009 @ 08:08 AM

  11. Eloy Duran
    Eloy Duran

    Do we need an additional check on the version of libxml that's installed? This is with a stock ruby install from 10.5.6

    Yes I think we do. The version that ships with OSX 10.5.x is 0.3.8.4, after installing 1.0.0 it works as expected.

    March 9th, 2009 @ 09:31 AM

  12. CancelProfileIsBroken
    CancelProfileIsBroken

    I'm seeing a failure on a Debian box with libxml-ruby 1.0.0:

    
    
    Name: test_expansion_count_is_limited(QueryTest) Type: Failure Message: <RuntimeError> exception expected but was Class: <LibXML::XML::Error> Message: <"Fatal error: Detected an entity reference loop at :12."> ---Backtrace--- ./test/../lib/active_support/xml_mini/libxml.rb:16:in `parse' ./test/../lib/active_support/xml_mini/libxml.rb:16:in `parse' ./test/../lib/active_support/core_ext/hash/conversions.rb:153:in `from_xml' ./test/core_ext/hash_ext_test.rb:903:in `test_expansion_count_is_limited' ./test/core_ext/hash_ext_test.rb:887:in `test_expansion_count_is_limited' /usr/local/lib/ruby/gems/1.8/gems/mocha-0.9.5/lib/mocha/test_case_adapter.rb:69:in `__send__' /usr/local/lib/ruby/gems/1.8/gems/mocha-0.9.5/lib/mocha/test_case_adapter.rb:69:in `run'
     
    

    This is using the standard Rails CI setup with just a few changes (like installing libxml-ruby) so it's a pretty clean test environment.

    March 9th, 2009 @ 12:37 PM

  13. Bart ten Brinke
    Bart ten Brinke

    Thats weird. How can the wrapper throw a different exception on Debian as on OSX? Currently I can't reproduce this because I had to send my Debian machine RMA :(. If I build fix, could you test it for me, Mike?

    March 9th, 2009 @ 12:44 PM

  14. CancelProfileIsBroken
    CancelProfileIsBroken

    Sure. Probably best to post any proposed patch here as I've heard a couple other reports of failure on os x this morning.

    March 9th, 2009 @ 12:58 PM

  15. Bart ten Brinke
    Bart ten Brinke

    Isn't that the libxml 1.0.0 version issue?

    March 9th, 2009 @ 01:01 PM

  16. Bart ten Brinke
    Bart ten Brinke

    I am using 0.9.7 on OSX BTW. I thought I was default. My bad.

    March 9th, 2009 @ 01:53 PM

  17. Bart ten Brinke
    Bart ten Brinke

    It seems that libxml-ruby 1.0.0 is pretty broken on OSX. Well at least it gives me a segfault on the recursion test ([BUG] Bus Error). I will make the patch libxml 0.9.7 specific if I can, but at the moment I haven't really got a good idea as how to do that.

    March 9th, 2009 @ 03:39 PM

  18. CancelProfileIsBroken
    CancelProfileIsBroken

    Seems like patch that ends up needing to target one specific version of the library should probably just be reverted until things are stabilized.

    March 9th, 2009 @ 03:47 PM

  19. Bart ten Brinke
    Bart ten Brinke

    I would think 1.0 would be stabilized :X. I think we should keep the XMLmini and rexml separation, but drop the LibXML implementation. It would be a shame as it really is a LOT faster.

    March 9th, 2009 @ 03:59 PM

  20. Bart ten Brinke
    Bart ten Brinke

    This limits it to libxml 0.9.4 and 0.9.7. Could you check it, Mike?

    March 9th, 2009 @ 04:12 PM

  21. Bart ten Brinke
    Bart ten Brinke

    I really feel strongly about the fact that ActiveResource needs a fast XML parser if it is to be considered as an option in any real world application.

    March 9th, 2009 @ 08:00 PM

  22. Michael Koziarski
    Michael Koziarski

    We could just adjust the defaults to always be rexml. Then let people do something like XmlMini.parser=:libxml to switch to the libxml implementation.

    As for the test failure for the ci box, that's actually fine. the test is really just meant to be testing "won't die when passed a loop" so the fact that libxml is raising a different error, is no big thing. Just need to adjust the test.

    March 9th, 2009 @ 08:05 PM

  23. Bart ten Brinke
    Bart ten Brinke

    You misunderstood. It raises something else in Debian 1.0.0, which is fine, but it segfaults in OSX, which is NOT fine.

    Wow, Jeremy fixed everything perfectly: http://github.com/rails/rails/co...

    Nice work!

    March 9th, 2009 @ 08:15 PM

  24. Michael Koziarski
    Michael Koziarski

    He has a habit of doing that :)

    If it's only our million-laughs test that causes a segfault, perhaps that should be included in a test case to upstream? Or are there additional cases which segfault?

    March 9th, 2009 @ 08:18 PM

  25. Bart ten Brinke
    Bart ten Brinke

    His fix however, is not working in my environment:

    ruby script/console Loading development environment (Rails 2.3.1)

    >> gem 'libxml-ruby', '=0.9.4', '=0.9.7' Gem::LoadError: RubyGem version error: libxml-ruby(0.9.4 not = 0.9.4, = 0.9.7)

    >> Gem.loaded_specs['libxml-ruby'].version.version => "0.9.7"

    March 9th, 2009 @ 08:29 PM

  26. Jeremy Kemper
    Jeremy Kemper

    What version of rubygems?

    March 9th, 2009 @ 08:36 PM

  27. Bart ten Brinke
  28. Jeremy Kemper
  29. Bart ten Brinke
    Bart ten Brinke

    That probably is the best solution :). Nice!

    March 9th, 2009 @ 08:56 PM

  30. Bart ten Brinke
    Bart ten Brinke

    The delegation seems to break if you switch it to libxml :(

    March 9th, 2009 @ 09:04 PM

  31. Bart ten Brinke
    Bart ten Brinke

    E(DELEGATION):2: warning: instance variable @backend not initialized. The libxml.rb does not return to the Xml_mini.rb flow after the mixin. I have no clue why not.

    March 10th, 2009 @ 07:35 AM

  32. Repository
    Repository

    (from [d4091d3bc79731f55491cfb51c604a66502c944f]) Properly set up libxml includes. Don't include LibXML in toplevel.

    [#2084 Alternative XML parsers support in ActiveSupport for ActiveResource state:resolved] http://github.com/rails/rails/co...

    March 10th, 2009 @ 06:58 PM

  33. Deleted User
    Deleted User

    Hey guys,

    Integrating libxml-ruby bindings in Rails would be great. But you positively, absolutely want to use libxml 1.1.1 and higher. Its the first version that works with ruby 1.9.1 and compiles cleanly on OS X. Let me know if you run into any issues and we'll get them cleaned up on our side.

    Charlie Savage (maintainer libxml-ruby).

    March 12th, 2009 @ 04:52 PM

  34. Jeremy Kemper
    Jeremy Kemper

    Hey Charlie, was 1.1.1 just released? The latest release segfaulted. 0.9.7 works and compiles fine on OSX (though not on 1.9).

    March 12th, 2009 @ 05:07 PM