From timb at metrumrg.com  Sat May 30 16:58:23 2009
From: timb at metrumrg.com (Tim Bergsma)
Date: Sat, 30 May 2009 10:58:23 -0400
Subject: [Rd] degraded performance with rank()
Message-ID: <ccac61760905300758y456d11c7i56f481ebb0e99063@mail.gmail.com>

Hi.

I'm maintaining a package that creates an object that is essentially a
classed version of numeric.  I updated recently from 2.7.1 to 2.9.0,
and merges involving my class suddenly took a huge performance hit.
I've traced the problem to something near rank().  From NEWS, it seems
rank() etc. changed in 2.8.0.  Methods for xtfrm() are supposed to
help, but I've had no success.  There was some chatter about this in
the archives back in Sept 08 (though apparently regarding S4), with a
suggestion that it is related to `[.` methods.  That has been my
experience.  In the toy example below, the problem disappears if
`[.my` is not defined.  Under R 2.7.1 on Mac, both cat() statements
take the same amount of time, and that time depends very little on the
length of x.  Under 2.9.0, the classed version takes much longer, and
the time grows (more than?) exponentially with length(x).

Is there something I can do to xtfrm.my() or [.my(), etc. to restore
the performance?

Thanks in advance,

Tim.

rm(list=ls())
as.my <- function(x,...)UseMethod('as.my')
as.my.default <- function(x,...)structure(x, class=c('my',class(x)))
`[.my` <- function (x, ...) structure(NextMethod("["), class = class(x))
xtfrm.my <- function(x)as.numeric(x)
x <- 1:10000
cat(system.time(rank(x))[3]);cat(' ')
cat(system.time(rank(as.my(x)))[3]);cat('\n')



[Rd] degraded performance with rank()
Tim Bergsma