Hello, I am looking for more information about lazy loading introduced in R 2.0.0. Doing ?lazyLoad I got some and there is a 'see also' section that points to 'makeLazyLoading'... But I cannot reach this page. My problem is: I recompiled a library that uses a lot of functions from other libraries (of course I can give details if needed). I load it in my computer: library(svGUI), and it takes something like 20 seconds to load. In R 1.9.1 it took 3-4 seconds on the same machine (Windows XP). So, I try now to understand the mechanism and to find a way to lower the loading time of this library with lazy loading (its goal is to load faster, isn't, so I probably do something wrong). Any help or advice would be appreciated. Here is a Rprof of library(svGUI) on my machine: ?? summaryRprof() $by.self self.time self.pct total.time total.pct file.exists 7.42 24.9 8.46 28.4 list.files 7.24 24.3 7.32 24.6 file 6.78 22.8 6.88 23.1 read.dcf 1.42 4.8 9.24 31.0 file.info 0.54 1.8 0.82 2.8 lapply 0.52 1.7 8.96 30.1 inherits 0.34 1.1 28.76 96.5 names 0.34 1.1 0.38 1.3 names<- 0.30 1.0 0.42 1.4 paste 0.30 1.0 0.66 2.2 close.connection 0.24 0.8 0.24 0.8 .Call 0.20 0.7 0.20 0.7 apply 0.20 0.7 0.58 1.9 .find.package 0.18 0.6 18.14 60.9 [... More here] $by.total total.time total.pct self.time self.pct library 29.70 99.7 0.00 0.0 try 29.64 99.5 0.10 0.3 f 29.36 98.5 0.00 0.0 firstlib 29.36 98.5 0.00 0.0 Require 28.96 97.2 0.00 0.0 match 28.80 96.6 0.08 0.3 inherits 28.76 96.5 0.34 1.1 is.factor 28.76 96.5 0.00 0.0 %in% 28.60 96.0 0.00 0.0 installed.packages 28.60 96.0 0.00 0.0 unlist 21.46 72.0 0.08 0.3 packageDescription 21.22 71.2 0.10 0.3 system.file 19.18 64.4 0.08 0.3 .find.package 18.14 60.9 0.18 0.6 guiInstall 11.82 39.7 0.00 0.0 read.dcf 9.24 31.0 1.42 4.8 lapply 8.96 30.1 0.52 1.7 file.exists 8.46 28.4 7.42 24.9 FUN 7.82 26.2 0.02 0.1 list.files 7.32 24.6 7.24 24.3 .packages 7.20 24.2 0.02 0.1 file 6.88 23.1 6.78 22.8 require 3.42 11.5 0.00 0.0 [... More here] This is the description of my package (in the bundle SciViews): Package: svGUI Title: SciViews GUI API - Main GUI features Description: Functions to communicate with a GUI client, to implement an object browser, etc... Bundle: SciViews Version: 0.7-0 Date: 2004-10-10 Depends: utils, grDevices, graphics, stats, methods, tcltk, R2HTML, svMisc Suggests: Hmisc, MASS, wxPython Author: Philippe Grosjean & Eric Lecoutre Maintainer: Philippe Grosjean <phgrosjean at sciviews.org> BundleDescription: SciViews GUI API A series of packages to implement a full reusable GUI API for R. License: GPL 2 or above URL: http://www.sciviews.org/SciViews-R Thank you. Best, Philippe Grosjean ..............................................<??}))><........ ) ) ) ) ) ( ( ( ( ( Prof. Philippe Grosjean ) ) ) ) ) ( ( ( ( ( Numerical Ecology of Aquatic Systems ) ) ) ) ) Mons-Hainaut University, Pentagone ( ( ( ( ( Academie Universitaire Wallonie-Bruxelles ) ) ) ) ) 6, av du Champ de Mars, 7000 Mons, Belgium ( ( ( ( ( ) ) ) ) ) phone: + 32.65.37.34.97, fax: + 32.65.37.33.12 ( ( ( ( ( email: Philippe.Grosjean at umh.ac.be ) ) ) ) ) ( ( ( ( ( web: http://www.umh.ac.be/~econum ) ) ) ) ) ..............................................................
Philippe Grosjean wrote:> Hello, > > I am looking for more information about lazy loading introduced in R 2.0.0. > Doing > ?lazyLoad > I got some and there is a 'see also' section that points to > 'makeLazyLoading'... But I cannot reach this page. > > My problem is: I recompiled a library that uses a lot of functions from > other libraries (of course I can give details if needed). I load it in my > computer: library(svGUI), and it takes something like 20 seconds to load. In > R 1.9.1 it took 3-4 seconds on the same machine (Windows XP). So, I try now > to understand the mechanism and to find a way to lower the loading time of > this library with lazy loading (its goal is to load faster, isn't, so I > probably do something wrong). > > Any help or advice would be appreciated. >Have you read the article about lazyLoad mechanism that Brian Ripley wrote for the latest R News issue?
Philippe Grosjean wrote:> Hello, > > I am looking for more information about lazy loading introduced in R 2.0.0. > Doing > ?lazyLoad > I got some and there is a 'see also' section that points to > 'makeLazyLoading'... But I cannot reach this page. > > My problem is: I recompiled a libraryPhilippe, citing Doug Bates: "Someone named Martin Maechler will shortly be sending you email regarding the distinction between 'library' and 'package'". ;-) [from: install.packages("fortunes") library(fortunes) fortune("library") ] > that uses a lot of functions from> other libraries (of course I can give details if needed). I load it in my > computer: library(svGUI), and it takes something like 20 seconds to load. In > R 1.9.1 it took 3-4 seconds on the same machine (Windows XP). So, I try now > to understand the mechanism and to find a way to lower the loading time of > this library with lazy loading (its goal is to load faster, isn't, so I > probably do something wrong).It might not always be faster. See Brian Ripley's article in the most recent R Newsletter. Probably you are using a lot of functions in the startup directly after the call to library() (in .First.lib() or .onLoad() or Hooks or whatever). I think you want to specify "LazyLoad: no" in the package's DESCRIPTION file (cp. "Writing R Extensions"). Uwe> Any help or advice would be appreciated. > > Here is a Rprof of library(svGUI) on my machine: > > ?? summaryRprof() > $by.self > self.time self.pct total.time total.pct > file.exists 7.42 24.9 8.46 28.4 > list.files 7.24 24.3 7.32 24.6 > file 6.78 22.8 6.88 23.1 > read.dcf 1.42 4.8 9.24 31.0 > file.info 0.54 1.8 0.82 2.8 > lapply 0.52 1.7 8.96 30.1 > inherits 0.34 1.1 28.76 96.5 > names 0.34 1.1 0.38 1.3 > names<- 0.30 1.0 0.42 1.4 > paste 0.30 1.0 0.66 2.2 > close.connection 0.24 0.8 0.24 0.8 > .Call 0.20 0.7 0.20 0.7 > apply 0.20 0.7 0.58 1.9 > .find.package 0.18 0.6 18.14 60.9 > [... More here] > > $by.total > total.time total.pct self.time self.pct > library 29.70 99.7 0.00 0.0 > try 29.64 99.5 0.10 0.3 > f 29.36 98.5 0.00 0.0 > firstlib 29.36 98.5 0.00 0.0 > Require 28.96 97.2 0.00 0.0 > match 28.80 96.6 0.08 0.3 > inherits 28.76 96.5 0.34 1.1 > is.factor 28.76 96.5 0.00 0.0 > %in% 28.60 96.0 0.00 0.0 > installed.packages 28.60 96.0 0.00 0.0 > unlist 21.46 72.0 0.08 0.3 > packageDescription 21.22 71.2 0.10 0.3 > system.file 19.18 64.4 0.08 0.3 > .find.package 18.14 60.9 0.18 0.6 > guiInstall 11.82 39.7 0.00 0.0 > read.dcf 9.24 31.0 1.42 4.8 > lapply 8.96 30.1 0.52 1.7 > file.exists 8.46 28.4 7.42 24.9 > FUN 7.82 26.2 0.02 0.1 > list.files 7.32 24.6 7.24 24.3 > .packages 7.20 24.2 0.02 0.1 > file 6.88 23.1 6.78 22.8 > require 3.42 11.5 0.00 0.0 > [... More here] > > This is the description of my package (in the bundle SciViews): > > Package: svGUI > Title: SciViews GUI API - Main GUI features > Description: Functions to communicate with a GUI client, to implement an > object browser, etc... > Bundle: SciViews > Version: 0.7-0 > Date: 2004-10-10 > Depends: utils, grDevices, graphics, stats, methods, tcltk, R2HTML, svMisc > Suggests: Hmisc, MASS, wxPython > Author: Philippe Grosjean & Eric Lecoutre > Maintainer: Philippe Grosjean <phgrosjean at sciviews.org> > BundleDescription: SciViews GUI API > A series of packages to implement a full reusable GUI API for R. > License: GPL 2 or above > URL: http://www.sciviews.org/SciViews-R > > Thank you. > Best, > > Philippe Grosjean > > ..............................................<??}))><........ > ) ) ) ) ) > ( ( ( ( ( Prof. Philippe Grosjean > ) ) ) ) ) > ( ( ( ( ( Numerical Ecology of Aquatic Systems > ) ) ) ) ) Mons-Hainaut University, Pentagone > ( ( ( ( ( Academie Universitaire Wallonie-Bruxelles > ) ) ) ) ) 6, av du Champ de Mars, 7000 Mons, Belgium > ( ( ( ( ( > ) ) ) ) ) phone: + 32.65.37.34.97, fax: + 32.65.37.33.12 > ( ( ( ( ( email: Philippe.Grosjean at umh.ac.be > ) ) ) ) ) > ( ( ( ( ( web: http://www.umh.ac.be/~econum > ) ) ) ) ) > .............................................................. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Problem solved! Adding a namespace speed up loading of my package by almost 30 times (around 1 sec)! Best, Philippe Grosjean> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of > Philippe Grosjean > Sent: Saturday, October 16, 2004 4:37 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Lazy loading... advices > > Hello, > > I am looking for more information about lazy loading > introduced in R 2.0.0. > Doing > ?lazyLoad > I got some and there is a 'see also' section that points to > 'makeLazyLoading'... But I cannot reach this page. > > My problem is: I recompiled a library that uses a lot of > functions from other libraries (of course I can give details > if needed). I load it in my > computer: library(svGUI), and it takes something like 20 > seconds to load. In R 1.9.1 it took 3-4 seconds on the same > machine (Windows XP). So, I try now to understand the > mechanism and to find a way to lower the loading time of this > library with lazy loading (its goal is to load faster, isn't, > so I probably do something wrong). > > Any help or advice would be appreciated. > > Here is a Rprof of library(svGUI) on my machine: > > ?? summaryRprof() > $by.self > self.time self.pct total.time total.pct > file.exists 7.42 24.9 8.46 28.4 > list.files 7.24 24.3 7.32 24.6 > file 6.78 22.8 6.88 23.1 > read.dcf 1.42 4.8 9.24 31.0 > file.info 0.54 1.8 0.82 2.8 > lapply 0.52 1.7 8.96 30.1 > inherits 0.34 1.1 28.76 96.5 > names 0.34 1.1 0.38 1.3 > names<- 0.30 1.0 0.42 1.4 > paste 0.30 1.0 0.66 2.2 > close.connection 0.24 0.8 0.24 0.8 > .Call 0.20 0.7 0.20 0.7 > apply 0.20 0.7 0.58 1.9 > .find.package 0.18 0.6 18.14 60.9 > [... More here] > > $by.total > total.time total.pct self.time self.pct > library 29.70 99.7 0.00 0.0 > try 29.64 99.5 0.10 0.3 > f 29.36 98.5 0.00 0.0 > firstlib 29.36 98.5 0.00 0.0 > Require 28.96 97.2 0.00 0.0 > match 28.80 96.6 0.08 0.3 > inherits 28.76 96.5 0.34 1.1 > is.factor 28.76 96.5 0.00 0.0 > %in% 28.60 96.0 0.00 0.0 > installed.packages 28.60 96.0 0.00 0.0 > unlist 21.46 72.0 0.08 0.3 > packageDescription 21.22 71.2 0.10 0.3 > system.file 19.18 64.4 0.08 0.3 > .find.package 18.14 60.9 0.18 0.6 > guiInstall 11.82 39.7 0.00 0.0 > read.dcf 9.24 31.0 1.42 4.8 > lapply 8.96 30.1 0.52 1.7 > file.exists 8.46 28.4 7.42 24.9 > FUN 7.82 26.2 0.02 0.1 > list.files 7.32 24.6 7.24 24.3 > .packages 7.20 24.2 0.02 0.1 > file 6.88 23.1 6.78 22.8 > require 3.42 11.5 0.00 0.0 > [... More here] > > This is the description of my package (in the bundle SciViews): > > Package: svGUI > Title: SciViews GUI API - Main GUI features > Description: Functions to communicate with a GUI client, to > implement an object browser, etc... > Bundle: SciViews > Version: 0.7-0 > Date: 2004-10-10 > Depends: utils, grDevices, graphics, stats, methods, tcltk, > R2HTML, svMisc > Suggests: Hmisc, MASS, wxPython > Author: Philippe Grosjean & Eric Lecoutre > Maintainer: Philippe Grosjean <phgrosjean at sciviews.org> > BundleDescription: SciViews GUI API > A series of packages to implement a full reusable GUI API for R. > License: GPL 2 or above > URL: http://www.sciviews.org/SciViews-R > > Thank you. > Best, > > Philippe Grosjean > > ..............................................<??}))><........ > ) ) ) ) ) > ( ( ( ( ( Prof. Philippe Grosjean > ) ) ) ) ) > ( ( ( ( ( Numerical Ecology of Aquatic Systems > ) ) ) ) ) Mons-Hainaut University, Pentagone > ( ( ( ( ( Academie Universitaire Wallonie-Bruxelles > ) ) ) ) ) 6, av du Champ de Mars, 7000 Mons, Belgium > ( ( ( ( ( > ) ) ) ) ) phone: + 32.65.37.34.97, fax: + 32.65.37.33.12 > ( ( ( ( ( email: Philippe.Grosjean at umh.ac.be > ) ) ) ) ) > ( ( ( ( ( web: http://www.umh.ac.be/~econum > ) ) ) ) ) > .............................................................. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >