Page 1 of 1

JSKitInterpreter performance enhancements

Posted: Mon May 19, 2008 4:55 pm
by ddribin
Hello,

Here's a patch for some performance enhancements when calling global functions. It cuts down the overhead of globalFunctionCallback() by ~25%-30%. It also includes my previous patch regarding memory leaks:

http://www.dribin.org/dave/tmp/interpre ... 1.patch.gz

The basic idea is to replace the dictionary entries in the global function dictionary with a custom object (JSKitFunctionEntry). I used Instruments to fine tune the overhead of calling Objective-C methods from JS.

I think we could tune it further by using a custom callback object, similar to JSKitBridgeInvocation. Instruments shows that a good portion of the overhead of calling an Objective-C method (in globalFunctionCallback()) is the wrapping of JSObjectRef function into an NSValue as well as looking up the function using objectForKey: on this NSValue. Using a custom callback object would eliminate the need for a dictionary lookup, since we can stash the invocation away in the private pointer. This should further reduce the overhead by another 20%-30%.

-Dave

Posted: Tue May 20, 2008 1:03 pm
by gandreas
Sweet!!!

I should probably take some time (maybe after WWDC) to set up a public svn repository (probably on SourceForge) to make things easier for this sort of update...

Posted: Fri May 23, 2008 1:11 am
by ddribin
Here's an updated version of this patch:

http://www.dribin.org/dave/tmp/interpre ... 1.patch.gz

Apply to a clean JSKit 0.1b1. It includes a new class in JSKore called JSKitObjCFunction. It's virtually the same as JSKitBridgeInvocation except it does not retain target. This could easily replace JSKitBridgeInvocation by adding a shouldRetainTarget property (though, perhaps non-retaining is better even for JSKitBridgeInvocation).

This is speeds up global function calls by about 25% compared to my previous patch, and about 50% faster than 0.1b1, vanilla.

-Dave

P.S. A public svn repo, would be great!

Posted: Tue May 27, 2008 1:11 pm
by gandreas
ddribin wrote:
P.S. A public svn repo, would be great!
I'm working on it...