Greetings Radnen!
Thanks for giving ClearScript a spin! This is great feedback.
We're actually encouraged by your numbers. When you use ClearScript with V8, calls across the managed/native boundary are indeed expensive. Since Jurassic avoids this transition by compiling JavaScript to CIL, we'd expect the code in your second example to still be faster with Jurassic than ClearScript.
So the question is, why is the code in your first example so much slower? The answer has to do with the way V8 embedding works. As is natural for JavaScript, V8 does not recognize any difference between properties and methods. The expression
We took a look and it turns out that we can fix this very easily for most managed objects and types. We've already coded the fix and will include it with the next release of ClearScript.
Thanks!
Thanks for giving ClearScript a spin! This is great feedback.
We're actually encouraged by your numbers. When you use ClearScript with V8, calls across the managed/native boundary are indeed expensive. Since Jurassic avoids this transition by compiling JavaScript to CIL, we'd expect the code in your second example to still be faster with Jurassic than ClearScript.
So the question is, why is the code in your first example so much slower? The answer has to do with the way V8 embedding works. As is natural for JavaScript, V8 does not recognize any difference between properties and methods. The expression
image.blit(0,0)
causes V8 to first retrieve the blit
property, and then to invoke its value as a function. Because image
is a managed object, this results in two round trips across the managed/native boundary. Eliminating one of them from the body of your loop - as the code in your second example does - makes a big difference.We took a look and it turns out that we can fix this very easily for most managed objects and types. We've already coded the fix and will include it with the next release of ClearScript.
Thanks!