From: John Miller Date: 2007-08-24T04:59:23+09:00 Subject: Re: Rope Data Structures >Just a musing on this, but if we want a fast and scalable rope structure >in Ruby (and speed and scalability are the reasons for using a rope, I >believe?), wouldn't it be better (though not quite so much fun) to >simply wrap a c / c++ rope library, rather than implement it from >scratch in Ruby? > >Perhaps it'd even be possible to get Ruby's string to switch internal >implementation using some huristics about its size. > >Cheers, > Benjohn I agree that for something like this a binary distribution is best, but they still cause problems in cross platform environments. (eg. JRuby) I think the best solutions are 1.) Have Multiple Gem distros (java, mswin32, source) and include a pure ruby version. Or 2.) integrate this into the interpreter core as another built in class. Pe単a, Botp wrote: > On Behalf Of John Miller: > # I tried writing a rope library in ruby and got an order of magnitude > # better performance when compared to a String implementation (6.5 to > 48.5 > > wow, that's quite a helpful boost. specially since a large percentage of > the web and database time is spent on string manipulation. post your > work as a gem, pls. > > kind regards -botp The ICFP task was written in such a way as to make maximum use of Ropes. I think that processing eRB template would also see pretty good gains. However, one must be careful to use Ropes only when string concatenation and slicing (Ropes do these in O(1) ) are much more common then accessing the string content (O(log(n)). An application where a string is build once and the accessed repeatedly will have poorer performance if it is converted to a rope. On the other hand a string that is repeatedly manipulated before finally being printed a single time will see performance gains proportional to the average length of the String/Rope. Databases do spend lots of time with strings, but there are many more accesses to strings then changes. Beyond that most of the strings that databases deal with are "short." I will see what I can do about getting out some sample code. John Miller -- Posted via http://www.ruby-forum.com/.