Quantcast
Are you the publisher? Claim or contact us about this channel


Embed this content in your HTML

Search

Report adult content:

click to rate:

Account: (login)

More Channels


Showcase


Channel Catalog



Channel Description:

ClearScript is a library that makes it easy to add scripting to your .NET applications. It currently supports JavaScript (via V8 and JScript) and VBScript.

older | 1 | .... | 41 | 42 | (Page 43) | 44 | 45 | .... | 115 | newer

    0 0
  • 07/31/14--12:29: New Post: Performance...
  • Hi ClearScript
    Answers below:

    ClearScript wrote:
    How are you measuring performance? For example, are you looking at the average time to process a request, average time within evaluateScript(), etc.?
    We are testing, with average time taken to call evaluateScript() (scenarios: string operations, numeric, array, ternary & conditional etc....)
    What do the scripts you're running look like, in general? How large are they? Are they static, or generated on the spot? How many different ones are there?
    Our scripts are generated on the fly, so we call the evaluateScript method above for each script block.
    the majority of our script blocks would be some sort of conditional expression (ie "xx" !=null && 1 > 0) something that would be in an 'if' expression.
    Do your scripts access host objects and/or types?
    No they do not.
    Does your application process multiple requests simultaneously? If so, what is your concurrency model?
    It is a web application running in IIS7/8, so it handles multiple requests via the worker processes. At an application level - it would be single threaded synchronous requests.
    The ClearScriptV8Scripting class above seems to provide no facility for disposing its internal V8ScriptEngine instance. Is that something you left out, or are you actually not disposing those instances?
    Nope i am not Disposing it! The entire request will be disposed when completed, that in-turn should dispose the V8Engine. But I can explicitly dispose it.


    Thanks,

    Jules

    0 0
  • 08/01/14--04:47: New Post: Performance...
  • Hi Jules,

    Thanks for your responses.
    ‚Äč
    So you're timing only the execution of very small scripts that are generated on the fly and don't access host resources. If that's correct, then it's likely that what you're measuring is mostly the overhead of invoking V8 via ClearScript, which is relatively high because of the transition from managed to native code. A 100% managed interpreter such as Jint might be a better fit for you.

    If you choose to stick with ClearScript and would like to improve your overall request processing throughput, consider using a pool of V8 engine instances instead of creating a new one for each request. Also, we strongly recommend that you dispose V8 instances explicitly; each instance reserves a very large block of address space, so it's important not to let them pile up until garbage collection takes place.

    Good luck!

    0 0

    Currently, I'm trying to figure out whether something like this is a safe thing to do:
    internal static class Program
    {
        private static void Main()
        {
            using (var engine = new JScriptEngine())
            {
                engine.AddHostObject(@"host", new HostFunctions(engine));
                Console.WriteLine(engine.Evaluate(@"host.RunIt()"));
            }
        }
    }
    
    public sealed class HostFunctions
    {
        private readonly ScriptEngine _engine;
    
        public HostFunctions(ScriptEngine engine)
        {
            _engine = engine;
        }
    
        public object RunIt()
        {
            return _engine.Evaluate(@"1+2");
        }
    }
    
    I.e. I'm executing a script and within the script, there is another call to the same scripting engine instance.

    My example above runs and works as expected, but it might be undefined behaviour, therefore I'm asking here.

    In my real world application I'm currently creating new engine instances each time a recursion is hit, but this seems to take a lot of overhead, so I'm trying to improve performance (see the following example).
    internal static class Program
    {
        private static void Main()
        {
            using (var engine = new JScriptEngine())
            {
                engine.AddHostObject(@"host", new HostFunctions());
                Console.WriteLine(engine.Evaluate(@"host.RunIt()"));
            }
        }
    }
    
    public sealed class HostFunctions
    {
        public object RunIt()
        {
            using (var engine = new JScriptEngine())
            {
                return engine.Evaluate(@"1+2");
            }
        }
    }
    I did some poor-man's benchmarking with the StopWatch .NET class and about 50,000 loops and it seems that the version with only one ScriptEngine instance is roughly about 30% faster than the one with multiple nested ScriptEngine instances.

    To sum up, I want to know whether this is supported:
    • Call Execute or Evaluate of one script engine instance recursively/nested
    • Do this on one thread only (so no multi-threading)

    0 0

    I have an application that is using VBS, JScript and V8 allowing me to switch easily between languages. All is working well but I notice that the 1st time I load the V8 Script Engine (and only this one) I get the following error message :
    A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

    My code is simply doing this
    if (v8engine == null) v8engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging);

    It does not seem to matter whether I have debugging Enabled or not.
    Whilst this is only a minor irritation it begs the question what is causing it and can I get rid of it.

    These are the files I have in my Exe folder (other than my App specific ones)
    21/06/2014 00:24 260,608 ClearScript.dll
    21/06/2014 00:24 615,936 ClearScript.pdb
    21/06/2014 00:24 192,061 ClearScript.xml
    21/06/2014 00:25 389,120 ClearScriptV8-32.dll
    21/06/2014 00:25 6,024,192 ClearScriptV8-32.pdb
    21/06/2014 00:28 3,361,280 v8-ia32.dll
    21/06/2014 00:28 4,140,032 v8-x64.dll

    0 0

    Hello!

    Yes, ClearScript's script execution methods support nested invocation.

    Cheers!

    0 0
  • 08/01/14--06:54: New Post: Performance...
  • Hi,

    Thanks for the response, I assumed this would be the overhead.

    Yes I am timing the overhead of invoking the 'evaluate' method repeatedly. Not the overhead of the creating the engine.

    Thanks for the suggestion.
    I have used jint ( as well as others - jurassic, ironjs, etc.. ) in the past and found they didn't preform as well as well to current managed version ecmascript-net library that i am using. I'm not sure what ecma level the library adheres to, but might be due to the performance gain.

    I will have a look again at Jint

    thank you for the help,

    Jules

    0 0

    Hi egooner,

    This exception is expected during the initialization of ClearScript's V8 support. It should be handled internally.

    The long story: ClearScript allows hosts to override its V8 assembly loading procedure via assembly resolution. If the host doesn't provide an assembly resolution handler, the runtime generates this exception; ClearScript handles it and continues with its normal loading procedure.

    If you're building ClearScript, you can eliminate the exception (along with the assembly resolution feature) by removing or commenting out these lines in ClearScript\V8\V8Proxy.cs:
    try
    {
        return Assembly.Load("ClearScriptV8");
    }
    catch (FileNotFoundException)
    {
    }
    Good luck!

    0 0

    Fixed dynamic script item invocation arguments for non-C# hosts.

    0 0

    Hi JC,

    The fix for the VB.NET issue is now available here.

    Thanks again!

    0 0

    I have this situation that it's not possible to install VC++ package on the server.
    Is there any alternative way to use ClearScript without VC++ package?

    0 0
  • 08/02/14--11:19: New Post: Performance...
  • In my own tests I found that the JScript engine of ClearScript is way faster than the V8 engine in ClearScript.

    I've did some looping with lots of creations of interpreters, here are some results:
    ClearScript JScript one interpreter per loop : 00:00:00.7287686.
    ClearScript JScript two interpreters per loop: 00:00:01.0320185.
    ClearScript JScript one interpreter          : 00:00:00.1482462.
    
    ClearScript V8 one interpreter per loop      : 00:00:54.8219984.
    ClearScript V8 two interpreters per loop     : 00:01:45.7223841.
    ClearScript V8 one interpreter               : 00:00:00.6268418.
    
    So you can see that the creation of engines is expensive but also with just one engine at all, JScript is still more than 4 times faster than V8.

    (I'm no performance experts, that are just tests I've documented here on Pastebin)

    0 0

    hi,
    i would implement my own AddEventHandler.
    my code:
    public class Window
        {
            private Form f;
            public Window(Form f)
            {
                this.f = f;
            }
    
            public void AddEventHandler(string name, dynamic handler)
            {
                f.GetType().GetEvent(name).AddEventHandler(f, Delegate.CreateDelegate(f.GetType(), new Action<string,string>((s, s1) => handler(s, s1)).Method));
            }
        }
    but it throws an exception: The type must be inferred from the delegate.
    Parameter name: type

    0 0
  • 08/03/14--04:36: New Post: ( expected
  • hello,

    my js:
    $(function(sender, e) {
                alert("hello to my EFML-Application :D");
                if(window.isXMLHttpRequest) {
                    var xml = new XMLHttpRequest();
                    xml.open("GET", "http://www.google.de/");
                    xml.onreadystatechange = function {
                        if(xml.readystate == 2) {
                            alert(xml.responsetext);
                        }
                    };
                }
            });
            window.onclose(function(sender, e) {
                alert("Application is closing");
            });
    but i think all is right

    0 0

    Codeplex failed to send me the update email. Thanks so much for the update!!!!

    -JC

    0 0

    Greetings!

    You should be able to use ClearScript's Windows script engine classes (JScriptEngine and VBScriptEngine) without installing the Visual C++ redistributable package. In fact, ClearScript.dll is the only ClearScript assembly you need if you aren't using V8.

    Good luck!

    0 0
  • 08/03/14--18:13: New Post: Performance...
  • Hello!

    There's no question that V8 is heavier and more complex than JScript, and for some use cases the latter is a better choice. V8 pays off when given larger, more complicated scripts to execute. For example, ClearScriptBenchmarks runs SunSpider about 15 times faster with V8 (option 3) than with JScript (option 1).

    Cheers!

    0 0

    Hi furesoft,

    It looks like you might want something like this:
    publicvoid AddEventHandler(string name, dynamic handler)
    {
        var evt = f.GetType().GetEvent(name);
        var action = new Action<object, object>((sender, args) => handler(sender, args));
        evt.AddEventHandler(f, Delegate.CreateDelegate(evt.EventHandlerType, action.Target, action.Method));
    }
    Keep in mind that ClearScript lets you set up event handlers directly from script code:
    form.Activated.connect(function (sender, args) {
        // do something
    });
    Good luck!

    0 0

    Dear Sir or Madam,
    I need to be able to pass in primitive types.

    I cannot use AddHostObject(). Calling AddHostObject() for boxed primitive types (double, int, etc.) raises exception "Invalid host item".

    I cannot use AddRestrictedHostObject(). Although exception is not raised when using AddRestrictedHostObject(), however, the resulted value cannot be used within the script: any arithmetic operation results in NaN.

    A workaround that I currently employed is to wrap the primitive type into a class or Array. I used Array successfully. However this is less convenient as a script writer would have to be aware of this. I wonder if it is possible to pass primitive types directly. Note that I cannot use 'engine.Script.p = 2.1' construct as parameters are added at run time and are not known during build.

    I would perhaps have expected something like AddHostValue(), but could find any.

    Sample script:
    function foo()
    {
    string s;

    try
    {
    double d = 2.1;
    object paramValue = (object)d;
    ScriptEngine engine = new JScriptEngine();
    // exception is rasied:
    engine.AddHostObject("p", paramValue);
    // same exception is rasied: engine.AddHostObject("p", d);
    // cannot do this: engine.Script.p = 2.1;
    }
    catch (Exception ex)
    {
    s = ex.Message;
    }
    }

    Please help,
    Yours faithfully

    MW

    0 0

    Dear Sir or Madam,
    I need to be able to pass in primitive types.

    I cannot use AddHostObject(). Calling AddHostObject() for boxed primitive types (double, int, etc.) raises exception "Invalid host item".

    I cannot use AddRestrictedHostObject(). Although exception is not raised when using AddRestrictedHostObject(), however, the resulted value cannot be used within the script: any arithmetic operation results in NaN.

    A workaround that I currently employed is to wrap the primitive type into a class or Array. I used Array successfully. However this is less convenient as a script writer would have to be aware of this. I wonder if it is possible to pass primitive types directly. Note that I cannot use 'engine.Script.p = 2.1' construct as parameters are added at run time and are not known during build.

    I would perhaps have expected something like AddHostValue(), but could find any.

    Sample script:
    function foo()
    {
    string s;

    try
    {
    double d = 2.1;
    object paramValue = (object)d;
    ScriptEngine engine = new JScriptEngine();
    // exception is rasied:
    engine.AddHostObject("p", paramValue);
    // same exception is rasied: engine.AddHostObject("p", d);
    // cannot do this: engine.Script.p = 2.1;
    }
    catch (Exception ex)
    {
    s = ex.Message;
    }
    }

    Please help,
    Yours faithfully

    MW
    Comments: The suggestion above appears to work, and MW hasn't sent an update in 10 days. Marking as resolved.

    0 0

    Ok, last question two questions, Mr. ClearScript.

    Here is my current scenario,
    1. I run a script which returns a string and I assign it to an object.
    2. The object returns the V8ScriptItem.
    3. Whenever I try to reference the object, for its value, it tries to invoke it as a script (or so it seems).
    Basic line of code I am using is below...
    c is an object but the function is returning a string.
    s1 is a string, CType is VBs way of casing, (String)
    c = JSEngine.Script.getChunkJSON(chunkNum)
    s1 = CType(c, String)
    The second line errors. Screenshot of the error and call stack can be found below.
    http://puu.sh/aDTlS/291299d450.png
    http://puu.sh/aDTir/407d48e142.png

    Any advice, or another way I should reference the result so it is seen as a value instead of a script to execute?


    Second question, should be a lot simpler... Could you show me show a cross between the Script.Method(args) and Engine.Evaluate("Code") would look like? My hope is to have a function that accepts a method name as a parameter and arguments as a second one like NeoLua used to.

    Engine.Evaluate(MethodName,Args[]);

    Thanks so much for your help and your continued support. BTW, the first fix works great.
    -JC

older | 1 | .... | 41 | 42 | (Page 43) | 44 | 45 | .... | 115 | newer