From: Ben Tilly Date: 2000-12-08T00:26:55+09:00 Subject: [ruby-talk:6899] Re: Some performance issues Hugh Sasse Staff Elec Eng wrote: > >On Thu, 7 Dec 2000, Ben Tilly wrote: > > > Glancing at array.c and string.c the reason for this is > > obvious. Strings in Ruby take up exactly the room > > allocated for them. Arrays are in a buffer where they > > have to be aligned on the left with the buffer but there > > is room on the right. Therefore any playing with the > > boundaries of a string forces you to recopy the whole > > thing. And likewise any playing with the left side of an > > array forces you to recopy it. (So shift should also be > [...] > > If Ruby wants good performance on this set of operations > > (trust me, people coming from Perl are going to be very > > likely to call shift a lot without realizing that it is > > slow) it needs to use a buffering system closer to that > > which Perl uses. In ruby.h this would mean adding a > > "capa" field to RString and an "offset" field to RArray, > > and adding logic in the C files to use these in an > [...] > >This seems odd to me, if I understand you. It sounds like >adding in extra padding so you can use it if you need it. That is exactly what it is. >I think the system of cons cells in lisp is quite nice. >This makes extending either end easy, and copes with nested >objects well. That is another very flexible system with a lot to say for it, but with drawbacks. >http://www.gnu.org/manual/elisp-manual-20-2.5/html_node/elisp_79.html > >and associated pages explain this. I don't know if it is >the best way to do it, but it could mean that iterating >through strings would use the same code as arrays, >substitution into strings would be easy. Making the list >doubly linked would ease bidirectional iteration at the >cost of memory. Fast access by [] would be more difficult, >which may be the reason for these other methods. One of the main promises of arrays is fast access by []. Also the regular expression library that Ruby uses assumes that it is dealing with C style strings. As well any extensions built in C will assume the same thing. So if Ruby wants to co-exist with the outside world it is good to have an internal implementation that isn't too strange to people you want to cooperate with. Oh yes, and the Lisp system takes up more memory than the buffering system. _____________________________________________________________________________________ Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com