[Bioc-devel] S4 Method Slow Execution if Signature Has Multiple Class Unions

Dario Strbenac d@tr7320 @end|ng |rom un|@@ydney@edu@@u
Mon Nov 22 22:00:03 CET 2021

Good day,

I created two constructor methods for a generic function. One is for the default empty constructor and the other is a constructor when any one or more parameters is specified by the user. The method signatures are:

1. c("missing", "missing", "missing", "missing", "missing", "missing", "missing", "missing"),
2. c("characterOrMissing", "numericOrMissing", "numericOrMissing", "numericOrMissing", "numericOrMissing", "characterOrMissing", "BiocParallelParamOrMissing", "numericOrMissing")

The class unions are defined as you might expect.

setClassUnion("characterOrMissing", c("character", "missing"))
setClassUnion("numericOrMissing", c("numeric", "missing"))
setClassUnion("BiocParallelParamOrMissing", c("BiocParallelParam", "missing"))

The first method works as expected:

> system.time(CrossValParams())
   user  system elapsed 
  0.165   0.000   0.165

The second takes over ten minutes and constantly uses 100% CPU usage, according to top.

> system.time(CrossValParams("Leave-k-Out", leave = 2))
   user  system elapsed 
760.018  15.093 775.090

Strangely, if I rerun this code again, it works quickly the second time.

> system.time(CrossValParams("Leave-k-Out", leave = 2))
   user  system elapsed 
  0.145   0.000   0.145

I haven't been able to come up with a minimal reproducile example of the issue. How can this be done consistently and efficiently?

Dario Strbenac
University of Sydney
Camperdown NSW 2050

More information about the Bioc-devel mailing list