[Rd] R_check_class_etc(x, valid) is "slow" when 'valid' contains class(x)

Tomas Kalibera tom@@@k@||ber@ @end|ng |rom gm@||@com
Fri Sep 2 11:30:06 CEST 2022


Hi Mikael,

On 8/28/22 01:13, Mikael Jagan wrote:
> R_check_class_etc(x, valid) spends a nontrivial amount of time finding
> an environment 'rho' containing the definition of class(x), evaluating
> (in R, not C) methods::.classEnv(class(x)).
>
> It then returns the result of R_check_class_and_super(x, valid, rho).
> But R_check_class_and_super() does not use 'rho' at all in the trivial
> case where class(x) is found in 'valid'.
right, that could be improved. Do you have an example which exhibits the 
problem, have you found this by profiling something?
>
> My feeling is that this can be improved.  I am happy to contribute a 
> patch,
> if it would be considered by R-core.

Both R_check_class_etc and R_check_class_and_super are unfortunately 
exported, the former is used a lot in packages (even though they are not 
mentioned in Writing R Extensions, so actually shouldn't be used in 
packages). Anyway, it would be easier if we could preserve their 
interface and behavior.

Maybe we could support rho==NULL in R_check_class_and_super, the 
environment would be looked up in that case when needed. 
R_check_class_etc would simply only call R_check_class_and_super with 
that argument. I see that R_check_class_and_super uses asChar() on the 
class attribute, while R_check_class_etc does not currently for looking 
for the environment, but I assume doing that in both cases should not 
matter (and it would have to be tested).

So this would be a trivial change, but if you wanted to create a minimal 
patch, I will be happy to have a look.

Best
Tomas


> Mikael
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list