[Rd] Increase transparency: suggestion on how to avoid namespaces and/or unnecessary overwrites of existing functions

Simon Urbanek simon.urbanek at r-project.org
Sun Oct 2 04:20:42 CEST 2011


On Oct 1, 2011, at 7:52 PM, Joshua Wiley wrote:

> On Sat, Oct 1, 2011 at 3:14 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>> On 11-10-01 5:14 PM, Dominick Samperi wrote:
> [snip]
>>> Except that namespace::foo should be assigned to another local
>>> variable instead of using package::foo in a tight loop, because
>>> repeated calls to "::" can introduce a significant performance
>>> penalty. (This has been discussed in another thread.)
>> 
>> That's good advice too.
>> 
>> Duncan Murdoch
> 
> Is this performance hit the sort of thing that byte compiling would help with, or am I misunderstanding its use?
> 

Depending on what you mean ;). If you mean that compiling code containing :: removes the issue, yes, that is indeed true (i.e., foo::bar gets compiled into the actual value since the compiler can assume that it is a constant and thus :: is not actually called).

If you mean that compiling base and thus :: then that helps only to a degree. According to microbenchmark the overhead of :: is in the order of 7.5ms when compiled and 11ms when not compiled on my test machine (Xeon X5690 and R-devel which is actually much faster than the 30ms in R 2.13.1). If the time spent in your actual function is in the order of  microseconds then the overhead is still huge in either case. If it's much bigger then either doesn't matter.

Cheers,
Simon



More information about the R-devel mailing list