Rev 69388 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
This branch contains modifications to the representation of data inSTRSXPs that tries to avoid creation of CHARSXP objects, or at leastdefer their creation until they are needed. Integers that areconverted to strings are initially stored as integers unless/untilthey are needed, thus avoiding the sprintf as well as creating theCHARSXP. (This is also done for doubles, but that probably isn't allthat useful.) Short ASCII strings are stored directly rather thanbeing boxed in CHARSXPs. The hope is that reducing the number ofCHARSXPs will reduce pressure on the GC.At this point the main example where this helps is in avoidingcreating case labels in lm(). In R-devel,> n <- 10000000> p <- 5> x <- matrix(rnorm(n * p), n, p)> y <- rnorm(n)>> system.time(lm(y ~ x))user system elapsed34.039 3.584 37.611> system.time(lm(y ~ x))user system elapsed22.645 3.118 25.755> system.time(lm(y ~ x))user system elapsed20.743 2.735 23.471With these changes, the timings are> system.time(lm(y ~ x))user system elapsed8.889 3.422 12.308> system.time(lm(y ~ x))user system elapsed8.688 3.400 12.083> system.time(lm(y ~ x))user system elapsed8.657 3.381 12.035This is clearly a useful improvement, but it can be had in other ways,so the question is whether there are benefits in other settings.Avoiding CHARSXP creation only for shorter strings may not be enough;an alternative is to initially allocate all string data contiguously,and only create CHARSXPs if elements are modified and new values donot fit. To go further it would be useful to have some benchmarks ofcode using character data.