From: Ruben Date: 2004-10-14T16:13:22+09:00 Subject: Re: GC and low file performance when large array is allocated At Thu, 14 Oct 2004 15:54:32 +0900, Geert Fannes wrote: > > Hello, > > I played some more with the test program and apparently it has nothing > to do with the file access. The program below is a simplified version, > which is more to the point. If I exchange the string allocation t="t" > with t=1, there is no performance drop anymore. > > # > #begin of program > # > allocateBefore=true > disableGC=false > > GC.disable if disableGC > > largeArray=Array.new(20000000) if allocateBefore > > 100000.times{|i|t="t"} > > largeArray=Array.new(20000000) if !allocateBefore > # > #end of program > # > > Any idea why the string allocation (and possibly deallocation) takes > so much more time when there is a large array in memory? Can I destroy > an object manually? This could be helpfull in combination with > disabling the garbage collection. > My guess is that in the loop 100000.times{|i|t="t"}, the garbage collector will run out of memory, maybe once, maybe even more. And when it runs out of memory, it will have to mark/read/follow all cells in "largeArray", and since that array is very large, i think that's causing the slowdown. Try the following and you'll see it's faster: # #begin of program # allocateBefore=true disableGC=false GC.disable if disableGC largeArray=Array.new(20000000) if allocateBefore largeArray=0 # explicitly setting to 0 so that the # gc will not need to mark it 100000.times{|i|t="t"} largeArray=Array.new(20000000) if !allocateBefore # #end of program # Ruben