IronJS
IronJS copied to clipboard
Loading coffee-script compiler is very slow
I'm trying to execute the Coffee-Script compiler ( https://raw.github.com/jashkenas/coffee-script/master/extras/coffee-script.js ) to bring it into scope and then use it to compile coffee-script into javascript
var ctx = new IronJS.Hosting.CSharp.Context();
ctx.ExecuteFile("coffee-script.js");
However the ExecuteFile call maxes out a CPU and never seems to stop. I left it running for over a minute. Any ideas what's going wrong, is the execution engine getting stuck in a tight loop?
I'm using IronJS v0.2
Make sure you are running in release mode. In debug mode, there is a lot going on to aid in debugging.
Can you try it in release mode and let us know if that works better?
Pulled master. Built Release.
Now when creating the context I get a TypeLoadException:
Could not load type 'IronJS.BoxedValue' from assembly 'IronJS, Version=0.2.1.0, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 4 that is incorrectly aligned or overlapped by a non-object field.
The code breaks into Hosting.fs line 211
let context =
FSharp.createContext()
Any ideas what's going wrong here? F# or 64 bit issues perhaps?
Changing my console application to be x86 instead of Any CPU seemed to fix that.
OK, so now it takes about 30 seconds to load the coffee-script compiler. Slow - but manageable for now I guess. However running the following code:
var ctx = new IronJS.Hosting.CSharp.Context();
ctx.ExecuteFile(@"..\..\coffee-script.js");
var coffeeScript = ctx.GetGlobal("CoffeeScript").Object;
var compile = coffeeScript.Get("compile").Func;
var js = compile.Call(coffeeScript, "a = x: 2").String;
Console.WriteLine(js);
Console.ReadLine();
Results in:
Unhandled Exception: System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.
at System.String.wstrcpy(Char* dmem, Char* smem, Int32 charCount)
at System.String.CopyTo(Int32 sourceIndex, Char[] destination, Int32 destinationIndex, Int32 count)
at System.IO.TextWriter.WriteLine(String value)
at System.IO.TextWriter.SyncTextWriter.WriteLine(String value)
at System.Console.WriteLine(String value)
at ConsoleApplication1.Program.Main(String[] args) at line 24
Why would a corrupt string be marshalled back from the JavaScript function call?
Hey!
First, we're looking into why the CoffeScript compiler is taking such a long time to load, there is something going on here that we haven't found that is slowing it down considerably. Sadly I haven't had time (can't speak for @otac0n) to look into it closer.
However, the problem you're experiencing is the problem the corrupt memory is because you're accessing the fields of the BoxedValue struct directly.
Basically where you're doing compile.Call(coffeeScript, "a = x: 2").String
you should not access .String
but rather rewrite the whole thee previous lines to look like this:
var coffeeScript = ctx.GetGlobalAs<IronJS.CommonObject>("CoffeScript");
var compile = coffeeScript.GetT<IronJS.FunctionObject>("compile");
var js = compile.Call(coffeeScript, "a = x: 2");
var source = IronJS.TypeConverter.ToString(js);
I'm aware the API is rather inconsistent!
Thanks for the quick response and letting me know the correct API calls. I was basically coding blind with Intellisense before :)
So, is this resolved for you? I know that we need to re-imagine the API to be more IntelliSense friendly...
ExecuteFile for the CoffeeScript compiler is still about 30 seconds for me (release build of IronJS). So can we leave this issue open until the cause of the slow loading has been tracked down?
Yeah, let's leave it open. I'll try to do some preliminary tests when I come home to track down the issue.
Hrm... here are my timings: Load CoffeeScript: 00:00:05.0645218 Compiling simple function: 00:00:03.8926191
I'm running Release, x86, on a 64 machine. (since that is what I have found to be the fastest.) Are you running an x86 or a 64-bit build?
Release x86 build running on Windows 7 64bit - MacBook Pro Intel Core2 Duo @ 2.4Ghz
Test program (also Release x86 build):
var ctx = new IronJS.Hosting.CSharp.Context();
var stopWatch = new Stopwatch();
stopWatch.Start();
ctx.ExecuteFile(@"..\..\coffee-script.js");
Console.WriteLine("Coffee-Script compiler loaded:");
Console.WriteLine(stopWatch.Elapsed.ToString());
stopWatch.Restart();
var coffeeScript = ctx.GetGlobalAs<IronJS.CommonObject>("CoffeeScript");
var compile = coffeeScript.GetT<IronJS.FunctionObject>("compile");
var js = compile.Call(coffeeScript, "a = x: 2");
var source = IronJS.TypeConverter.ToString(js);
Console.WriteLine("Simple code compiled:");
Console.WriteLine(stopWatch.Elapsed.ToString());
Console.WriteLine(source);
Output:
Coffee-Script compiler loaded:
00:00:28.8578343
Simple code compiled:
00:00:05.4059259
(function() {
var ;
a = {
x: 2
};
}).call(this);
Also note the incorrect JavaScript being generated! var ;
should be var a;
With an AnyCPU release build, I get 10s to load the compiler, but I get the same var ; problem.
Anything I could do to help ?
The 'var ;' thing should be fixed as of about 9:00 Central last night. Can you try grabbing the most recent version off of NuGet, or pulling 'master' again.
ok i'll try that, and I tell you.
cheers
http://thinkbeforecoding.com
On Wed, Jun 29, 2011 at 1:33 PM, otac0n < [email protected]>wrote:
The 'var ;' thing should be fixed as of about 9:00 Central last night. Can you try grabbing the most recent version off of NuGet, or pulling 'master' again.
Reply to this email directly or view it on GitHub: https://github.com/fholm/IronJS/issues/43#issuecomment-1466343
Nice, it's working fine. Thanks.
Thanks for the fix. I'm still seeing ~30 seconds to load the CoffeeScript compiler, but at this point correctness is more important than performance :)
No problem. We'll keep this issue open to track the current performance issues with compilation.
I also experience the issue of CoffeScript "hanging" when being compiled. Additionaly to the lag, I experience a huge memory load, especially when run as 64 bit process. The process aborts with an OutOfMemoryException after allocating nearly 4GB.
Interesting... I'll see if I can repro. What version of CoffeeScript are you using?
I believe this was with Version 1.1.0.