ra.png

The Ra Extension to R

Ra is functionally identical to R but provides just-in-time compilation of loops and arithmetic expressions in loops. This usually makes arithmetic in Ra much faster. Ra will also typically run a little faster than standard R even when just-in-time compilation is not enabled.

An example

    jit(1)                     # turn on just-in-time compilation
    for(i in 1:na)             # example convolution code 
      for(j in 1:nb)
        ab[i+j-1] <- ab[i+j-1] + a[i] * b[j]
With na and nb bigger than about 100, the loop runs about 30 times faster. With na and nb equal to 10, the loop runs about 10 times faster. See here for timing tests.

The idea is that all you have to do is add a jit(1) statement before loops. The R code is compiled on the fly to bytecode which is executed internally by an interpreter in C.

It's ready now

Ra works and has been thoroughly tested, although it is not an "official" R project. It's not just a proof-of-concept project.

It's not a panacea

The JIT compiler makes arithmetic loops faster, but not other code. The jit statement must be inserted by the programmer before loops. You will not see speed increases in most existing packages.

Documentation

A case study (an overview document using the distribution-of-determinant example).

The help page describes the jit() function. It is part of the jit package on CRAN. The jit package works in conjunction with the Ra executables. Under R, the jit() function has no effect.

Timing tests
Implementation notes (describe the design approach)
Reading List
Some email with replies
Internal data structures (JPEG file)
Internal state machine (PDF file)

Windows download

On a Windows system, the simplest way to install Ra is to run the Windows Ra 1.2.7 Win32 installer (11 May 2009, based on R 2.9.0, about 1.3 MBytes). It's easy and you get the benefit of a faster version of R. You need to first have R 2.9.0 installed. You should uninstall your old version of Ra, if any, before installing a new version.

This README file tells you what the installer does.
The case study will give you an idea of what Ra can and can't do.

Source code

Current release 11 May 2009 ra_1.2.7.tar.gz based on the R-2.9.0 sources.
NEWS summarizes changes in each release.
Build instructions (also included in the tar file).
Remember to also install the jit package from CRAN.

Debian release prepared by Dirk Eddelbuettel
Simon Urbanek reports that Ra builds cleanly on Linux and Mac OS X.

Previous releases

Future work

Future work will extend the range of compilable R constructs and increase the speed of the just-in-time code execution machine. The documentation also needs work.

Any volunteers? Have a look at the big switch in evaljit.c and evaljit1.c which if replaced would more than double the speed of jitted code.

Request for feedback

Your comments would be appreciated. Please use milbo AT sonic PERIOD net.

Acknowledgments

It is a pleasure to thank the following people for their contribution to Ra:
To Stephen Milborrow Homepage