logo
  • Jobs
  • About Me
  • Contact
  • Home
« RailsEnvy.com
Site update »

Slow .rxml processing

Posted March 13th, 2008 by Matt Berther

There has been a performance issue that has been well documented when using Builder::XMLMarkup. Over the course of time, I’d noticed that my rails app has gotten slower and slower building XML as more data ended up in the database. On my development environment, it would take approximately 15 seconds to render the xml generated by this controller.

As it turns out, the pure ruby implementation of String#to_xs is pretty slow. Thankfully, there is a C extension which you can install to alleviate this. Installing fast_xs is as easy as:

superbia:~ matt$: sudo gem install fast_xs

If you’re using Rails 2.0, you’re done. If you’re using Rails 1.2.x, we’ll do some monkey patching to make this essentially a drop-in fix. We’ll utilize the same techniques that are used to address the issue in Rails 2.0. Essentially, we want to extend String to take advantage of the fast_xs method if it is available. To do this, open $(RAILS)/config/environment.rb and add the following lines to the bottom.

begin
  require 'fast_xs'
 
  class String
    alias_method :original_xs, :to_xs if method_defined?(:to_xs)
    alias_method :to_xs, :fast_xs
  end
rescue LoadError
  #fast_xs extension unavailable
end
 

Again, this is exactly how Rails 2.0 takes care of it for you. By the way, this one single change dropped my render time from roughly 15 seconds to just under 3 seconds. If you’re building a lot of XML with Builder::XMLMarkup, you need to take a look at this.

This entry was posted on Thursday, March 13th, 2008 at 11:35 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
-->

Social
  • mattberther on twitter
Syndication
Archives
  • November 2008
  • September 2008
  • August 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • December 2004
  • November 2004
  • October 2004
  • September 2004
  • August 2004
  • July 2004
  • June 2004
  • May 2004
  • April 2004
  • March 2004
  • February 2004
  • January 2004
  • December 2003
  • November 2003
  • October 2003
  • September 2003
  • August 2003
  • July 2003
  • June 2003
  • May 2003
  • April 2003
  • March 2003
Jobs
mattberther.com © 2003 - 2008