[Rd] Speeding up library loading

Duncan Murdoch murdoch at stats.uwo.ca
Tue Apr 26 08:29:53 CEST 2005


Ali - wrote:
> 
> 
>>> Lazy loading just converts an object into a small instruction to load 
>>> the object. If the object was already small, there's no advantage to 
>>> that.  It's mainly designed to avoid memory use (some rarely used 
>>> objects can be gigantic).
>>
>>
>> From a design point of view the reason is that this isn't the problem 
>> lazy loading is trying to solve. We didn't have a problem with 
>> packages that have huge number of small objects, but we did have a 
>> problem with packages that had a moderate number of moderately large 
>> objects.
>>
>> In addition, trying to optimize performance is not usually a good idea 
>> unless you can measure the performance of different implementations on 
>> real applications, and we didn't have applications like that.
> 
> 
> Assume 100 C++ classes each class having 100 member functions. After 
> wrapping these classes into R, if the wrapping design is class-oriented 
> we should have like 100 objects. At the same time, if the wrapping 
> design is function-oriented we have like 10`000 objects which are too 
> lazy for lazy loading.
> 
> I have tried wrapping exactly the same classes by R.oo based on S3 and 
> the outcome package was much faster in both installation and loading. 
> The package went slow once I tried it with S4. I guess R.oo makes the 
> package more class-oriented while S4 object-orientation is really 
> function-oriented causing all this friction in installation and loading.
> 
> Is there any way to ask R to lazy-load each object as a 'bundle of S4 
> methods with the same class'?

I don't think so.  There are ways to load a bundle of objects all at 
once (put them in an environment, attach the environment), but S4 
methods aren't self-contained, they need to be registered with the 
system.   You could probably write a function to load them and register 
them all at once, but I don't think it exists now.

Duncan Murdoch



More information about the R-devel mailing list