Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've figured it out!</p> <p>The problem was in the <code>sapply()</code> call. <code>sapply</code> does a fair amount of renaming and property setting which slows things down massively for arrays of this size. Replacing <code>DecodeSpectrum</code> with the following code brought the sample time from <code>14.66</code> seconds down to <code>3.36</code> seconds, a 4-fold increase!</p> <p>Here's the new body of <code>DecodeSpectrum</code>:</p> <pre><code>DecodeSpectrum &lt;- function(array_length, mz_array, intensity_array) { ## needed to tell `vapply` how long the result should be. No, there isn't an ## easier way to do this. resultLength &lt;- rep(1.0, array_length) vapply(list(mz_array=mz_array, intensity_array=intensity_array), readBin, resultLength, what="double", endian="little", n=array_length, USE.NAMES=FALSE) } </code></pre> <p>The <code>Rprof</code> output now looks like:</p> <pre><code>$by.self self.time self.pct total.time total.pct "&lt;Anonymous&gt;" 0.64 19.75 2.14 66.05 "DecodeSpectrum" 0.46 14.20 1.12 34.57 ".Call" 0.42 12.96 0.42 12.96 "FUN" 0.38 11.73 0.38 11.73 "&amp;" 0.16 4.94 0.16 4.94 "&gt;" 0.14 4.32 0.14 4.32 "c" 0.14 4.32 0.14 4.32 "list" 0.14 4.32 0.14 4.32 "vapply" 0.12 3.70 0.66 20.37 "mapply" 0.10 3.09 2.54 78.40 "simplify2array" 0.10 3.09 0.30 9.26 "&lt;" 0.08 2.47 0.08 2.47 "t" 0.04 1.23 2.72 83.95 "as.vector" 0.04 1.23 0.08 2.47 "unlist" 0.04 1.23 0.08 2.47 "lapply" 0.04 1.23 0.04 1.23 "unique.default" 0.04 1.23 0.04 1.23 "NextSegment" 0.02 0.62 0.50 15.43 "odbcFetchRows" 0.02 0.62 0.46 14.20 "unique" 0.02 0.62 0.10 3.09 "array" 0.02 0.62 0.04 1.23 "attr" 0.02 0.62 0.02 0.62 "match.fun" 0.02 0.62 0.02 0.62 "odbcValidChannel" 0.02 0.62 0.02 0.62 "parent.frame" 0.02 0.62 0.02 0.62 $by.total total.time total.pct self.time self.pct "ProcessAllSegments" 3.24 100.00 0.00 0.00 "t" 2.72 83.95 0.04 1.23 "do.call" 2.68 82.72 0.00 0.00 "mapply" 2.54 78.40 0.10 3.09 "&lt;Anonymous&gt;" 2.14 66.05 0.64 19.75 "DecodeSpectrum" 1.12 34.57 0.46 14.20 "vapply" 0.66 20.37 0.12 3.70 "NextSegment" 0.50 15.43 0.02 0.62 "odbcFetchRows" 0.46 14.20 0.02 0.62 ".Call" 0.42 12.96 0.42 12.96 "FUN" 0.38 11.73 0.38 11.73 "simplify2array" 0.30 9.26 0.10 3.09 "&amp;" 0.16 4.94 0.16 4.94 "&gt;" 0.14 4.32 0.14 4.32 "c" 0.14 4.32 0.14 4.32 "list" 0.14 4.32 0.14 4.32 "unique" 0.10 3.09 0.02 0.62 "&lt;" 0.08 2.47 0.08 2.47 "as.vector" 0.08 2.47 0.04 1.23 "unlist" 0.08 2.47 0.04 1.23 "lapply" 0.04 1.23 0.04 1.23 "unique.default" 0.04 1.23 0.04 1.23 "array" 0.04 1.23 0.02 0.62 "attr" 0.02 0.62 0.02 0.62 "match.fun" 0.02 0.62 0.02 0.62 "odbcValidChannel" 0.02 0.62 0.02 0.62 "parent.frame" 0.02 0.62 0.02 0.62 $sample.interval [1] 0.02 $sampling.time [1] 3.24 </code></pre> <p>It's possible that some additional performance could be squeezed out of messing with the <code>do.call('mapply', ...)</code> call, but I'm satisfied enough with the performance as is that I'm not willing to waste time on that.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload