Monday, September 29, 2008

Eval vs. Closure

Yesterday I made some experiments with respect to the relative speed of using closures vs. eval. For Joose these are the two options when creating accessor methods for attributes.
The results are quite interesting
  • On average executing a function that is not a closure and was created using eval is 30% faster than executing a closure
  • However, creating a function using eval takes about 200 times longer on worst case (FF3 on OSX)
This means using eval would create some significant gains for if you are executing an accessor method many times (you will need to be in the 10th of thousands for it to make a noticable difference). However, the increased cost for actually creating the function is currently prohibitive. With Joose we make sure that the compile time remains very small, because it will directly affect your page load time.

Thus, this will not go into Joose by default. We might still, however, create an option that lets you enable compiling accessors with eval for single attributes which are used very heavily.
Post a Comment