Hi,
there was a memory improvement done in R going from R 3.3.3 to R 3.4.0 when it comes to comparing an integer 'x' an double 'y' (either may be scalar or vector). For example, in R 3.3.3, I get: > getRversion() [1] '3.3.3' > x <- integer(1000) > y <- double(1000) > profmem::profmem(z <- (x < y)) Rprofmem memory profiling of: z <- (x < y) Memory allocations: bytes calls 1 8040 <internal> 2 4040 <internal> total 12080 > and in R 3.4.0, I get: > getRversion() [1] '3.4.0' > x <- integer(1000) > y <- double(1000) > profmem::profmem(z <- (x < y)) Rprofmem memory profiling of: z <- (x < y) Memory allocations: bytes calls 1 4040 <internal> total 4040 Note how in R (<= 3.3.3), the (x < y) comparison will cause an internal coercion of integer vector 'x' into a double, which then can be compared to double 'y'. In R (>= 3.4.0), it appears that this coercion is done per element and will therefore avoid introducing a new, temporary copy internally. The same is observed with when comparing with (x == y). This is a great improvement that I think deserves more credit. I couldn't find any mentioning of it in the R 3.4.0 NEWS (https://cran.r-project.org/doc/manuals/r-release/NEWS.html). Does anyone know whether this was a specific improvement for such comparison, or a side effect of something else, e.g. an improved byte compiler? Thanks, Henrik ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-devel |
Thanks for highlighting this. I just made the change one day. Guess I
should have mentioned it in the NEWS. Michael On Sat, Jan 27, 2018 at 3:01 PM, Henrik Bengtsson < [hidden email]> wrote: > Hi, > > there was a memory improvement done in R going from R 3.3.3 to R 3.4.0 > when it comes to comparing an integer 'x' an double 'y' (either may be > scalar or vector). > > For example, in R 3.3.3, I get: > > > getRversion() > [1] '3.3.3' > > x <- integer(1000) > > y <- double(1000) > > profmem::profmem(z <- (x < y)) > Rprofmem memory profiling of: > z <- (x < y) > > Memory allocations: > bytes calls > 1 8040 <internal> > 2 4040 <internal> > total 12080 > > > > and in R 3.4.0, I get: > > > getRversion() > [1] '3.4.0' > > x <- integer(1000) > > y <- double(1000) > > profmem::profmem(z <- (x < y)) > Rprofmem memory profiling of: > z <- (x < y) > > Memory allocations: > bytes calls > 1 4040 <internal> > total 4040 > > Note how in R (<= 3.3.3), the (x < y) comparison will cause an > internal coercion of integer vector 'x' into a double, which then can > be compared to double 'y'. In R (>= 3.4.0), it appears that this > coercion is done per element and will therefore avoid introducing a > new, temporary copy internally. The same is observed with when > comparing with (x == y). > > This is a great improvement that I think deserves more credit. I > couldn't find any mentioning of it in the R 3.4.0 NEWS > (https://cran.r-project.org/doc/manuals/r-release/NEWS.html). Does > anyone know whether this was a specific improvement for such > comparison, or a side effect of something else, e.g. an improved byte > compiler? > > Thanks, > > Henrik > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-devel |
Free forum by Nabble | Edit this page |