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

The simplest way to install Ra is to run the Windows Ra 1.1.1 Win32 installer (15 Jul 2008, based on R 2.7.1, 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.7.1 installed. You should uninstall your old version of Ra 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.
Thanks to Søren Højsgaard for his help with the installer.

Source code

Current release 15 Jul 2008 ra_1.1.1.tar.gz based on the R-2.7.1 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 Ra 1.1.1 prepared by Dirk Eddelbuettel
Simon Urbanek reports that Ra builds cleanly on Linux and Mac OS X.

Previous releases:
ra_1.1.0.tar.gz|Ra 1.1.0 Win32 installer based on the R-2.7.0 sources.
ra_1.0.9.tar.gz|Ra 1.0.9 Win32 installer based on the R-2.7.0 sources.
ra_1.0.7.tar.gz|Ra 1.0.7 Win32 installer based on the R-2.6.2 sources.
ra_1.0.6.tar.gz| ra_1.0.5.tar.gz| ra-04.tar.gz| ra-03.tar.gz.

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? There is some low hanging fruit. 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.

To Stephen Milborrow Homepage