[R-pkg-devel] speeding up package code/build/test cycle

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Thu Jun 24 22:31:14 CEST 2021


On 24/06/2021 3:44 p.m., Gábor Csárdi wrote:
> On Thu, Jun 24, 2021 at 8:55 PM Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
> [...]
>> A disadvantage of the devtools method is that a regular build after
>> load_all() seems to do a full 75 sec build:  load_all caches things for
>> itself, but doesn't put them in the same place as a regular build, so
>> make doesn't see the object files, and rebuilds all of them.  Or at
>> least it did that last time I tried it, a few months ago.
> 
> That is definitely not how load_all() should work, so this might be a
> bug. AFAIK it does not use a special cache or anything, just compiles
> the files inside the package tree, like a regular package install from
> a package tree. This is a regular install after load_all():
> 
> ❯ system.time(devtools::load_all())
> ℹ Loading rgl
> This build of rgl does not include OpenGL functions.  Use
>   rglwidget() to display results, e.g. via options(rgl.printRglwidget = TRUE).
>     user  system elapsed
>    0.411   0.024   0.446
> 
> ❯ q()
> 
> ❯ time R CMD INSTALL .
> * installing to library ‘/Users/gaborcsardi/Library/R/4.0/library’
> [...]
> * DONE (rgl)
> R CMD INSTALL .  9.95s user 1.28s system 97% cpu 11.503 total
> 
> So a load_all() that does not need to recompile anything, just reload
> the R code, takes less than half a second. After that a regular
> install from the command line takes about 12s, most of which is the
> byte compilation. If I turn byte compilation off, then it is less than
> 6s.
> 
> But it is rare that you actually need to install the package while
> working on it, and you typically just use load_all() to iterate, or
> devtools::test() if you use testthat.

I'm working in RStudio on a Mac, in case that makes any difference. 
I've just done the following:

1.  devtools::load_all(".")

This does a full compile of the C++ source, so it's slow.

2.  devtools::load_all(".")

No recompile, so really quick.

3.  Click "Install and Restart" button

This does R CMD INSTALL --pre-clean ....  so it's really slow.

4.  Click "Install and Restart" button again

This is the fast build I was talking about:  no recompiling.

5.  devtools::load_all(".")

This does the full compile again, so it's slow.

So it appears that "Install and Restart" doesn't trust the object files 
that load_all() produced, and load_all() doesn't trust the object files 
that R CMD INSTALL produced.

This might be influenced by my choice not to "Use devtools package 
functions" in the Build Tools menu.  Probably the slow compile in step 3 
is an RStudio issue, not a devtools issue:  it used different command 
line options.  But the slow compile in step 5 looks like a devtools issue.

Your last paragraph is incorrect if "you" is taken to be me rather than 
a generic developer:  I *often* want to install the package while 
working on it.  I like the help system to work; I like to work on the 
source code and help pages together.  That may not be typical. 
Certainly help pages seem to be a low priority in most tidyverse packages.

Duncan Murdoch



More information about the R-package-devel mailing list