From simon.urbanek at r-project.org  Sun Oct  2 04:20:42 2011
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Sat, 1 Oct 2011 22:20:42 -0400
Subject: [Rd] Increase transparency: suggestion on how to avoid
	namespaces and/or unnecessary overwrites of existing functions
In-Reply-To: <CANz9Z_JpcPWLOTfTTuehWeqH0Kt46fV2vEEbn5431qDVqPE_Hw@mail.gmail.com>
References: <4E53F02F.106@googlemail.com> <4E874909.7060308@gmail.com>
	<CADUbQ5giQwm7bS6Xx+tYwLVKOEvJ7yy66rUTJ_oimF0YUcJWPg@mail.gmail.com>
	<4E8790B9.3030500@gmail.com>
	<CANz9Z_JpcPWLOTfTTuehWeqH0Kt46fV2vEEbn5431qDVqPE_Hw@mail.gmail.com>
Message-ID: <D867B746-CEF9-4FFC-97E2-97A1AE032855@r-project.org>


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



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