For some web services I need to speed up on demand ggplot2 plots as much as possible. With the introduction of memoise, some caching is automatically introduced on the plotting functions, making the second plot significantly faster than the first one. However my web service only draws 1 plot per R session, so this doesn't help by default.
I was wondering if it would be wise/possible/useful to do precaching (e.g. do some calculations onload, before the actual request), or save/load memoise caches to disk for common calls + output.
An example:
> library(ggplot2);
> pdf(tempfile());
> system.time(print(qplot(speed, dist, color=speed, data=cars, geom=c("point", "smooth"))));
user system elapsed
0.496 0.008 0.512
> system.time(print(qplot(speed, dist, color=speed, data=cars, geom=c("point", "smooth"))));
user system elapsed
0.312 0.004 0.322
AFAIK, the memoise
package only supports in-session cache. If you quit an R session, you lose the cache. I'm not sure if the cacheSweave
/knitr
model helps for your web service, but I believe you have to write the cached results in the disk anyway like these two packages. If the same code is run (verify by MD5), you simply load the cache. You might provide an example so I can know the problem better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With