[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

XML builder performance

Xin Zheng

10/31/2008 1:01:00 PM

Hi all,

I have been doing some performance testing, and have noticed it takes
significantly longer to render a XML output then a HTML one. It made me
think perhaps there's a faster way of generating XML than using XML
builder.

I did a quick search and did not find any alternatives, or anyone
talking about XML builder's performance issues.

Is there anyway of optimizing XML Builder? Or is there a faster
alternative?
--
Posted via http://www.ruby-....

11 Answers

Xin Zheng

10/31/2008 2:23:00 PM

0

Dan Webb wrote:
> The only Ruby Library I've found in the last 2 weeks that seems to do
> XMl output is: http://www.tutorialspoint.com/ruby/ruby_xm...
>
> However the builder API is nice and for me personally worth the slightly
> longer output. However saying that I managed to output 100 records to
> XML within 10 seconds and I don't think it's builder slowing things
> down.

Thanks for the reply.

I'm using it to output KML on the fly, so every half a second counts. At
the moment, it's taking .5 seconds longer to generate a small-ish file
than it takes for the HTML output.

If there are no clear drop-in alternatives, I might leave off optimising
my KML outputs.

Thanks,
Xin
--
Posted via http://www.ruby-....

Avdi Grimm

10/31/2008 2:25:00 PM

0

On Fri, Oct 31, 2008 at 9:01 AM, Xin Zheng <crazygecko@gmail.com> wrote:
> I have been doing some performance testing, and have noticed it takes
> significantly longer to render a XML output then a HTML one. It made me
> think perhaps there's a faster way of generating XML than using XML
> builder.

The standard answer for XML performance issues in Ruby is to switch to
libxml-ruby.

--
Avdi

Home: http:...
Developer Blog: http:.../devblog/
Twitter: http://twitte...
Journal: http://avdi.livej...

Xin Zheng

10/31/2008 2:32:00 PM

0

> The standard answer for XML performance issues in Ruby is to switch to
> libxml-ruby.

Isn't libxml-ruby is used for parsing XML? Where as I only need to
output XML.


--
Posted via http://www.ruby-....

Avdi Grimm

10/31/2008 2:44:00 PM

0

On Fri, Oct 31, 2008 at 10:32 AM, Xin Zheng <crazygecko@gmail.com> wrote:
> Isn't libxml-ruby is used for parsing XML? Where as I only need to
> output XML.

You can build and output XML with it. See for instance the Node documentation:

http://libxml.rubyforge.org/rdoc/classes/LibXML/XML...

--
Avdi

Home: http:...
Developer Blog: http:.../devblog/
Twitter: http://twitte...
Journal: http://avdi.livej...

James Gray

10/31/2008 2:52:00 PM

0

On Oct 31, 2008, at 9:32 AM, Xin Zheng wrote:

>> The standard answer for XML performance issues in Ruby is to switch
>> to
>> libxml-ruby.
>
> Isn't libxml-ruby is used for parsing XML? Where as I only need to
> output XML.

Have you tried some stupid simple solution like just building the
string manually?

James Edward Gray II

ara.t.howard

10/31/2008 4:17:00 PM

0


On Oct 31, 2008, at 7:01 AM, Xin Zheng wrote:

> Hi all,
>
> I have been doing some performance testing, and have noticed it takes
> significantly longer to render a XML output then a HTML one. It made
> me
> think perhaps there's a faster way of generating XML than using XML
> builder.
>
> I did a quick search and did not find any alternatives, or anyone
> talking about XML builder's performance issues.
>
> Is there anyway of optimizing XML Builder? Or is there a faster
> alternative?

try tagz

# gem install tagz

require 'tagz'


xml = Tagz{ foo_{ bar_(:key => :value){ 42 } } }

http://codeforp...lib/ruby/tagz/tagz-4....

a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Frederick Cheung

10/31/2008 4:39:00 PM

0


On 31 Oct 2008, at 13:01, Xin Zheng wrote:

> Hi all,
>
> I have been doing some performance testing, and have noticed it takes
> significantly longer to render a XML output then a HTML one. It made
> me
> think perhaps there's a faster way of generating XML than using XML
> builder.
>
> I did a quick search and did not find any alternatives, or anyone
> talking about XML builder's performance issues.
>
> Is there anyway of optimizing XML Builder? Or is there a faster
> alternative?

I remember looking at this a while back and it turns out that a
significant bottleneck is how builder escapes your text (look in the
builder source for to_xs). It's doing a lot more that it has too
(although I don't deny that a lot of the time that will be useful).
There's a gem (fast_xs) which implements that in C and makes that
bottleneck a lot faster.

Fred

Mark Thomas

10/31/2008 6:36:00 PM

0

I agree with Avdi. LibXML will be the fastest builder-library
solution.

If you want a friendlier interface you can try Nokogiri (http://
nokogiri.rubyforge.org/) which is a wrapper for LibXML.

-- Mark.

Aaron Patterson

11/1/2008 5:51:00 PM

0

On Fri, Oct 31, 2008 at 10:01:14PM +0900, Xin Zheng wrote:
> Hi all,
>
> I have been doing some performance testing, and have noticed it takes
> significantly longer to render a XML output then a HTML one. It made me
> think perhaps there's a faster way of generating XML than using XML
> builder.
>
> I did a quick search and did not find any alternatives, or anyone
> talking about XML builder's performance issues.
>
> Is there anyway of optimizing XML Builder? Or is there a faster
> alternative?

How large are the documents you're trying to build? If they are small,
I recommend faster-builder:

http://github.com/codahale/faster-builder/t...

Unfortunately its speed diminshes a lot as the number of nodes increase.
If the documents are large, you should try Nokogiri's builder. I found
it to be faster for larger documents than faster-builder.

Here is my benchmark: http://gist.github...

Here is some example builder code:

http://github.com/tenderlove/nokogiri/wiki...

--
Aaron Patterson
http://tenderlovem...

Aaron Patterson

11/1/2008 5:51:00 PM

0

On Sat, Nov 01, 2008 at 03:39:01AM +0900, Mark Thomas wrote:
> I agree with Avdi. LibXML will be the fastest builder-library
> solution.
>
> If you want a friendlier interface you can try Nokogiri (http://
> nokogiri.rubyforge.org/) which is a wrapper for LibXML.

Just so there is no confusion, Nokogiri wraps the libxml2 C library.
Not the LibXML ruby library. :-)

--
Aaron Patterson
http://tenderlovem...