Skip to content
Prev 22053 / 63424 Next

S4 generics, modify() generic and modifyList() ...

On Thu, 21 Sep 2006, Martin Maechler wrote:
[...]
Please no: that would have a 'dramatic' effect on startup times for the 
'lean and mean' R used as a scripting engine when building R (that often 
uses utils).

Try

gannet% cat > test.R
proc.time()
library(methods)
proc.time()
q()
gannet% env R_DEFAULT_PACKAGES='utils' Rbeta --slave < test.R 
[1] 0.124 0.016 0.125 0.000 0.000
[1] 0.632 0.040 0.657 0.000 0.000

so methods would increase the startup time ca 5x.  There has been no 
discernable progress on the cost of startup of methods when there are no 
S4 generics in the other packages: it is slower than all the other default 
packages put together.  Similarly, there is a considerable cost to S3 
dispatch of having an S4 take-over of S3 generics (especially internal 
generics).

Good 'R-izens' need to consider the environmental impact of their use of 
S4 code.  One thing we may be getting closer to is not making 'methods' a 
default package at all, but loading it only when needed.  (Now S4 objects 
can be identified easliy, that could be checked when one is 
created/loaded.) It is like the on-going debate on 4x4 vehicles (SUVs to 
Americans), which carry a lot of extra weight for off-road features that 
are almost never used.