This project has moved and is read-only. For the latest updates, please go here.

Performance Improvements

Feb 24, 2014 at 2:25 PM

performance is really important in our application. That's why we switched from Jurassic to ClearScript. Now we have much better results, but I still found some places in ClearScript code, that could be improved. I made these improvements and the execution of one of our scripts is now more then two times faster then without these improvements. I have quite special case - milions of JavaScript objects mapped to .Net objects. But I still think, these improvements may help also to some other people. May I create fork in your repository and upload the changes? Maybe you will like them and include them to the main branch.

Anyway, great work on ClearScript. It's well created and really easy to use.

Thanks, Libor.
Feb 24, 2014 at 4:02 PM
Hi Libor,

That sounds great! Please feel free to fork the code and add your changes. And thanks for your positive feedback!

Feb 24, 2014 at 5:14 PM

I've commited updates in the new created fork. I hope, it will be usefull ;-)

Feb 26, 2014 at 3:41 PM
Hello Libor,

Thanks for sharing your optimizations. We particularly like your idea of having host items partially share their cached type information. This is definitely something we'll explore further.

By the way, if you're using V8 in a performance-critical application, we recommend using V8ScriptEngineFlags.DisableGlobalMembers if possible.

Also, if you're comfortable sharing it, we'd love to hear more about your application, specifically the aspects that require large numbers of exposed objects.

Thanks again!
Feb 27, 2014 at 10:01 AM

the application is used for virtualization of services (SOAP, REST, JDBC, MQ, ...) generaly for testing of distributed systems (QA can test the system before all the neccessary services are ready and also can easily change behavior of the services and test, how the tested system works with different conditions).
Very simply said our application recieves request message and have to generate and send response message. One of the ways, how the application can modify the response is to modify or partially create it in using JavaScript. And here is the place, where ClearScript is used. The message is stored in a tree structure and user can modify or change any value in the tree and I have to know, what exactly did the user set in the tree not only what did he changed, I have also to know, if user sets some value that was already there. Thas why the simple diff of the original tree and the result of the script execution is not good enought. I have to map the tree to the ClearScript and trace all the objects set into it.
Some scripts are fast (run few ms) but not all of them. We have also script, where millisons of objects are created and added to the tree in for-cycle.

I've already tried to use V8ScriptEngineFlags.DisableGlobalMembers but it did wasn;t faster. In what cases should it help?

After fixing the performance issues I've found in ClearScript, profiler shows me weak places in my app. Is some better way, how can I do this calls faster?

1) Getting property names from object created in JavaScript:
2) Check if the object is an array:
..just once:
  isArrayFunction = clearScriptEngine.V8ScriptEngine.Evaluate("(function (x) { return x instanceof Array; })");
..and than use lot of times:
3) Getting the property value:
dynamicObject.TryGetMember(new Binder(propertyName, false), out propertyValue)
I've also tried to get property value using CallSite. But it was slower even when I was chaching the CallSites.

Thanks, Libor.
Feb 27, 2014 at 9:06 PM
Edited Mar 3, 2014 at 1:11 PM
Hi Libor,

Thanks for describing your application. It sounds like you have things well in hand, having profiled your application. We've been focusing mostly on ease of use, but we expect performance to occupy more of our cycles as we hear more real-world feedback like yours. In the meantime, you can see most of our current performance-oriented recommendations in this thread.

I've already tried to use V8ScriptEngineFlags.DisableGlobalMembers but it did wasn;t faster. In what cases should it help?

It helps in scenarios where script code frequently accesses the global object. Check out the ClearScriptBenchmarks application; SunSpider performs much better with that flag than without.