From seth at userprimary.net  Tue Apr 27 22:33:06 2010
From: seth at userprimary.net (Seth Falcon)
Date: Tue, 27 Apr 2010 13:33:06 -0700
Subject: [Rd] Resolving functions using R's namespace mechanism can
 double runtime
In-Reply-To: <g2gd4cf43b61004271316p316d0d64ya9e53412b8a8df73@mail.gmail.com>
References: <g2gd4cf43b61004271316p316d0d64ya9e53412b8a8df73@mail.gmail.com>
Message-ID: <4BD74A02.8080901@userprimary.net>

On 4/27/10 1:16 PM, Dominick Samperi wrote:
> It appears that the runtime for an R script can more than double if a few
> references to a function foo() are replaced by more explict references
> of the form pkgname::foo().
>
> The more explicit references are of course required when two
> loaded packages define the same function.
>
> I can understand why use of this mechanism is not free in an
> interpreted environment like R, but the cost seems rather high.

`::` is a function, so there is going to be overhead.  OTOH, there is no 
reason to pay for the lookup more than once.  For example at startup, 
you could do:

myfoo <- pkgname::foo

And then later call myfoo() and I don't think you will see the added cost.

You can formalize the above approach in package code by renaming 
function in the importFrom directive where I believe you can do:

importFrom(pkgname, myfoo=foo)


+ seth

-- 
Seth Falcon | @sfalcon | http://userprimary.net/



[Rd] Resolving functions using R's namespace mechanism can double runtime
Seth Falcon