Skip to content
Prev 32607 / 398530 Next

Slow computation in for loop

Philippe Grosjean wrote:
Got it in one.  This is one place where Splus performance is much better 
than R.  Some simulations I did makes it look like Splus does not just 
enlarge objects one element at a time. Instead, the underlying memory is 
enlarged in larger increments and additions to the array use this hidden 
space.

I thought about adding this feature, but in the end decided that 
pre-allocating the result is a better solution (the Splus enlargement 
strategy doesn't work when elements are prepended).  At one one point 
there was a slot in the object header which could have served to hold 
the "true length" of objects, but I think that Luke Tierney has used it 
for other puposes.