Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: ScriptItem performance

$
0
0
Hi blackshade,

Why the use of dynamics?

.NET's dynamic infrastructure provides a convenient way to access script objects in a way that's both .NET-friendly and engine-neutral. A dictionary-style interface might also be convenient, but it's not clear what advantage it would have over the combination of GetDynamicMemberNames() and dynamic indexing.

The problem with your GetMember() method is that it recreates the binder and callsite each time. Try this instead:
privatestaticobject GetMember(object o, string propName) {
    return ((dynamic)o)[propName];
}
This implementation is simpler and takes advantage of inline caching to speed up repeated calls. In our experiments it's about 22x faster on average in Release builds.

Still, using JSON tunneling as you suggest makes sense in many cases. ClearScript provides live access to script objects, but if all you need is a snapshot, then JSON is a great way to minimize marshaling and improve performance.

Thanks for your question, and good luck!

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>