JSKitInterpreter performance enhancements

Discuss the JavaScriptCore Objective-C wrapper/bridge
Post Reply
ddribin
Posts: 19
Joined: Mon May 12, 2008 9:21 am

JSKitInterpreter performance enhancements

Post by ddribin » Mon May 19, 2008 4:55 pm

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

gandreas
Immortal
Posts: 1464
Joined: Wed Feb 04, 2004 6:02 pm
Contact:

Post by gandreas » Tue May 20, 2008 1:03 pm

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...

ddribin
Posts: 19
Joined: Mon May 12, 2008 9:21 am

Post by ddribin » Fri May 23, 2008 1:11 am

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!

gandreas
Immortal
Posts: 1464
Joined: Wed Feb 04, 2004 6:02 pm
Contact:

Post by gandreas » Tue May 27, 2008 1:11 pm

ddribin wrote:
P.S. A public svn repo, would be great!
I'm working on it...

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests