Skip to content
Prev 49724 / 63424 Next

:: and ::: as .Primitives?

I'm not convinced that how to make :: faster is the right question. If
you are finding foo::bar being called often enough to matter to your
overall performance then to me the question is: why are you calling
foo::bar more than once? Making :: a bit faster by making it a
primitive will remove some overhead, but your are still left with a
lot of work that shouldn't need to happen more than once.

For default methods there ought to be a way to create those so the
default method is computed at creation or load time and stored in an
environment. For other cases if I want to use foo::bar many times, say
in a loop, I would do

foo_bar <- foo::bar

and use foo_bar, or something along those lines.

When :: and ::: were introduce they were intended primarily for
reflection and debugging, so speed was not an issue. ::: is still
really only reliably usable that way, and making it faster may just
encourage bad practice. :: is different and there are good arguments
for using it in code, but I'm not yet seeing good arguments for use in
ways that would be performance-critical, but I'm happy to be convinced
otherwise. If there is a need for a faster :: then going to a
SPECIALSXP is fine; it would also be good to make the byte code
compiler aware of it, and possibly to work on ways to improve the
performance further e.g. through cacheing.

Best,

luke
On Thu, 22 Jan 2015, Peter Haverty wrote: