Hi - First off: great job on this ClearScript!
I have a question about performance when invoking many small script blocks in a web application - short explanation:
I have implemented a ClearScriptV8 version and tested with performance about 10x slower than what I have now.
The implementation is very simple - essentially a new ClearScriptV8Scripting instance is created per request, and during that call many requests to evaluateScript are called.
Thanks,
Jules
I have a question about performance when invoking many small script blocks in a web application - short explanation:
- I have a proprietary language that utilizes JavaScript as it's scripting language. It is an interpreted language written in .net (so its an interpreted, interpreted language!).
- It is a web based application and a 'scripting' context is created per request.
- At run-time, all conditions/logic etc are all evaluated with calls to the scripting engine.
-
My current scripting engine is an older Rhino port (https://code.google.com/p/ecmascript-net/) that is all managed (good performance) but not sure how well maintained/documented.
I have implemented a ClearScriptV8 version and tested with performance about 10x slower than what I have now.
The implementation is very simple - essentially a new ClearScriptV8Scripting instance is created per request, and during that call many requests to evaluateScript are called.
public class ClearScriptV8Scripting : IScriptEngine
{
private V8ScriptEngine engine;
public ClearScriptV8Scripting()
{
engine = new V8ScriptEngine();
}
public String evaluateScript(String script)
{
Object result = engine.Evaluate(script);
return (result == null || result is Microsoft.ClearScript.Undefined) ? string.Empty : result.ToString();
}
public String callFunction(String function, String[] parameters)
{
Object result = engine.InvokeFunction(function, parameters);
return result == null ? string.Empty : result.ToString();
}
public String[] convertToArray(String strArr)
{
dynamic arr = engine.Evaluate(strArr);
String[] result = new String[arr.length];
for (int i = 0; i < arr.length; i++)
{
result[i] = arr[i].ToString();
}
return result;
}
}
//extension for calling a function directly from c#
public static class ClearScriptEngineExtensions
{
public static object InvokeFunction(this Microsoft.ClearScript.ScriptEngine engine, string name, object[] args)
{
var host = new HostFunctions();
((IScriptableObject)host).OnExposedToScriptCode(engine);
var del = (Delegate)host.func<object>(args.Length, engine.Script[name]);
return del.DynamicInvoke(args);
}
}
I'm just curious if anyone has any ideas on how I can improve performance my performance ?Thanks,
Jules