r-lib / pkgbuild

Find tools needed to build R packages
https://pkgbuild.r-lib.org
Other
65 stars 33 forks source link

slow package compiles after ubuntu update #154

Closed ecmerkle closed 1 year ago

ecmerkle commented 1 year ago

Hello, I have an R package (blavaan) that compiles an rstan model during installation. When I am developing the package, I typically load new changes via

pkgload::load_all(<package_dir>, export_all=FALSE, compile=TRUE)

After upgrading from Ubuntu 20.04 (focal) to Ubuntu 22.04 (jammy), I noticed that the compilation time is much longer using the above command, and the subsequent Stan model runs an order of magnitude slower than it previously did. But if I build the same package via R CMD build and then install it via install.packages(), the compilation proceeds as normal and the Stan model is fast again.

I am guessing that my system is the problem but also wondered whether you've heard of anything like this before. In case it helps, my R package is on github here. Thanks!

gaborcsardi commented 1 year ago

pkgload::load_all() creates a debug build by default, as it is for package development. Set the PKG_BUILD_EXTRA_FLAGS=false env var if you want a release build, see the README.

ecmerkle commented 1 year ago

Thank you, that solved it! In case it helps anyone, I added the following line to ~/.Renviron

PKG_BUILD_EXTRA_FLAGS="false"

This is probably not optimal if you want to switch back and forth between debug build and release build, but it is what I was searching for.

cdriveraus commented 1 year ago

Just stumbled on this thread from elsewhere, the default of a debug build caused me lots of headaches previously, was not aware it could be changed so easily -- just a small vote for a different default from me.

gaborcsardi commented 1 year ago

pkgload::load_all() is primarily for development, hence the default.

If you want to use a package, the best is to install it, instead of using load_all().

cdriveraus commented 1 year ago

maybe it is an rstudio issue, but I've had cases where this debug build is triggered by a request to document the package -- the build is not able to complete, and it breaks the existing installation.

gaborcsardi commented 1 year ago

That's possible, dependending on your project options. You can set "Always use --preclean when installing package" to make sure that a clean build is installed instead of a debug build.

cdriveraus commented 1 year ago

the problem with preclean is that it will always recompile the software, which is unnecessary :/

gaborcsardi commented 1 year ago

Well, it is necessary, if previously it was compiled as a debug build.

pkgbuild/pkgload could store the debug build in a different directory I guess.

cdriveraus commented 1 year ago

Yes but it has never compiled successfully as a debug build, the comment is unrelated to that. with preclean on, unnecessary compilations happen, with preclean off, debug builds are attempted which fail and break the installation, necessitating a new (non debug) build.

gaborcsardi commented 1 year ago

Right, then you need to set that env var, and debug builds are never produced.

And in general, I think

  1. we could put debug builds in a different directory, and
  2. give more control for what kind of builds are produced by load_all().