From milbo at sonic.net  Wed Aug 29 22:18:39 2007
From: milbo at sonic.net (Stephen Milborrow)
Date: Wed, 29 Aug 2007 13:18:39 -0700
Subject: [Rd] Modifying R_CheckStack for a speed increase
Message-ID: <000f01c7ea79$d55b95c0$6401a8c0@DDV3JY61>

Greetings R developers,

R will run a little faster when executing "pure R" code if the function
R_CheckStack() is modified.

With the modification, the following code for example runs 15% faster
(compared to a virgin R-2.5.1 on my Windows XP machine):

      N = 1e7
      foo <- function(x)
      {
           for (i in 1:N)
                x <- x + 1
          x
      }
      foo(0)

The crux of the modification is to change the following line in 
R_CheckStack()

      if(R_CStackLimit != -1 && usage > 0.95 * R_CStackLimit) {...

to

      if(usage > R_CStackLen) { ...

Details and modified sources can be found at
ftp://ftp.sonic.net/pub/users/milbo.

Regards,
Stephen

http://milbo.users.sonic.net



[Rd] Modifying R_CheckStack for a speed increase
Stephen Milborrow