{"action":"created","issue":{"url":"https://api.github.com/repos/paulbartrum/jurassic/issues/15","repository_url":"https://api.github.com/repos/paulbartrum/jurassic","labels_url":"https://api.github.com/repos/paulbartrum/jurassic/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/paulbartrum/jurassic/issues/15/comments","events_url":"https://api.github.com/repos/paulbartrum/jurassic/issues/15/events","html_url":"https://github.com/paulbartrum/jurassic/issues/15","id":146298188,"number":15,"title":"Compilation to a dll","user":{"login":"CPardi","id":10943153,"avatar_url":"https://avatars.githubusercontent.com/u/10943153?v=3","gravatar_id":"","url":"https://api.github.com/users/CPardi","html_url":"https://github.com/CPardi","followers_url":"https://api.github.com/users/CPardi/followers","following_url":"https://api.github.com/users/CPardi/following{/other_user}","gists_url":"https://api.github.com/users/CPardi/gists{/gist_id}","starred_url":"https://api.github.com/users/CPardi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CPardi/subscriptions","organizations_url":"https://api.github.com/users/CPardi/orgs","repos_url":"https://api.github.com/users/CPardi/repos","events_url":"https://api.github.com/users/CPardi/events{/privacy}","received_events_url":"https://api.github.com/users/CPardi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/paulbartrum/jurassic/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2016-04-06T12:25:42Z","updated_at":"2016-04-09T12:22:33Z","closed_at":null,"body":"Hi, from what I understand Jurassic creates IL code from the JavaScript code and then runs the IL. This creates some overhead in the first calls of functions. Of course, this is necessary if you want to run scripts at runtime from C#. However, I am interested in using some JavaScript libraries from C# and so the Javascript code would remain the same from one run to the next. So I was wondering, is there some way to save the generated IL as a dll to effectively remove the startup overhead? Cheers"},"comment":{"url":"https://api.github.com/repos/paulbartrum/jurassic/issues/comments/207782595","html_url":"https://github.com/paulbartrum/jurassic/issues/15#issuecomment-207782595","issue_url":"https://api.github.com/repos/paulbartrum/jurassic/issues/15","id":207782595,"user":{"login":"CPardi","id":10943153,"avatar_url":"https://avatars.githubusercontent.com/u/10943153?v=3","gravatar_id":"","url":"https://api.github.com/users/CPardi","html_url":"https://github.com/CPardi","followers_url":"https://api.github.com/users/CPardi/followers","following_url":"https://api.github.com/users/CPardi/following{/other_user}","gists_url":"https://api.github.com/users/CPardi/gists{/gist_id}","starred_url":"https://api.github.com/users/CPardi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CPardi/subscriptions","organizations_url":"https://api.github.com/users/CPardi/orgs","repos_url":"https://api.github.com/users/CPardi/repos","events_url":"https://api.github.com/users/CPardi/events{/privacy}","received_events_url":"https://api.github.com/users/CPardi/received_events","type":"User","site_admin":false},"created_at":"2016-04-09T12:22:33Z","updated_at":"2016-04-09T12:22:33Z","body":"I had a play around and got a little further. It appears that the method cache `Jurassic.Compiler.GeneratedMethod.generatedMethodCache` is not repopulated by any method outputted in the IL. I am using the code below to create the DLL with the `ScriptCompiler.Save()` method [here](https://github.com/CPardi/jurassic/blob/CompileToDll/Jurassic/Core/ScriptCompiler.cs). Please ignore the comments, I was playing with Reflection.Emit.\r\n\r\n```cs\r\n        private static void JurassicCompileTest()\r\n        {\r\n            var sw = new Stopwatch();\r\n\r\n            // Create an engine.\r\n            var compiler = new ScriptCompiler();\r\n\r\n            // Create a Javscript object using Javscript object initializer.\r\n            sw.Restart();\r\n            compiler.IncludeInput(\"var test = { 'foo' : 'bar', 'bar':'foo' };\");\r\n            compiler.IncludeInput(\"var helloWorldAndTest = function() { return JSON.stringify(test); };\");\r\n            Console.WriteLine(sw.ElapsedMilliseconds / 1000.0);\r\n\r\n            compiler.Save(\"Test.dll\");\r\n        }\r\n```\r\n\r\nI've had some success when I try to repopulate manually using the code below which uses the `ScriptCompiler.Load()` method.\r\n\r\n```cs\r\n        private static void CompiledJurassicTest()\r\n        {\r\n            var sw = new Stopwatch();\r\n\r\n            // Create an engine.\r\n            \r\n            var compiler = new ScriptCompiler();\r\n            var engine = compiler.Load(\r\n                new Func<ScriptEngine, Scope, object, object>[] { JavaScriptClass0.global_, JavaScriptClass1.global_ },\r\n                new[] { new FunctionDelegate((a, b, c, d, e) => JavaScriptClass2.anonymous(a, b, c, d, e)) });\r\n\r\n            engine.SetGlobalFunction(\"log\", new Action<string>(Console.WriteLine));\r\n            Console.WriteLine(engine.CallGlobalFunction(\"helloWorldAndTest\"));\r\n\r\n        }\r\n```\r\n\r\nDoes this seem a reasonable thing to do? I am thinking of \r\n * In the Load method using reflection to find all `.anonymous` methods and add them to the `GeneratedMethod.generatedMethodCache` and then find the '.global_' methods in each type and run them on the ScriptEngine."}}