Wow, this is an awesome project! I wrote a home automation system and implemented a simple rules system in XML (essentially If-Then-Else statements). As I wanted to do more complex things in my rules, I decided to look around for a way to host a scripting
language directly so that I don't end up writing one over time. ClearScript does this so easily that I am just amazed. Thank you for releasing the project and for all the support you give in these forums; they have been a great resource for me.
So, 2 questions:
2) I want to have an implementation of some XmlHttpRequest features. As discussed previously in some topics here, this can easily be done by wrapping WebClient and I see how to do this on both sides of the fence. Is there a performance or garbage collection
contrast between these 2 approaches:
Sep 9, 2015 at 9:07 PM
Edited Sep 9, 2015 at 9:07 PM
First, thank you very much for your positive feedback!
Now, on to your questions:
Most likely it's because invoking a .NET method from script code involves an expensive step (called
) that maps the method name to a unique method. For an overloaded method this step may require an examination of the argument types, and for a generic method it may require the on-demand construction of the specialized (closed generic) version
of the method.
Once a given call signature has been bound successfully, ClearScript caches the binding to speed up subsequent calls. This is very similar to what happens at
call sites emitted by the C# compiler.
If you're concerned about performance and/or wish to restrict the script's activities, then exposing a simple, custom API is probably the best approach. The key for performance is to design your API to minimize hops across the .NET-script boundary, especially
if you're using V8. That script engine is remarkably fast but not as fast as JIT-compiled C#, and the overhead of invoking native code from .NET is significant.