Replies: 3 comments 2 replies
-
Hi @koculu, Your project, Topaz, looks fantastic! Thanks for releasing it on GitHub! There's no question that V8 heavily favors script execution speed over startup time and memory efficiency, and that the boundary between the managed host and the V8 environment is expensive. If your application depends on chatty host-script interaction, V8 is probably not for you, especially if your scripts are small and not computationally intensive. As for concurrency, the usual way to achieve it in JavaScript is by using multiple engine instances that communicate via message passing. Web Workers are an example of this approach. We've posted a sample that demonstrates a similar facility implemented with ClearScript. By the way, we modified the Topaz benchmark to print results for Topaz, Jint, and ClearScript. On our test machine, it produces the following output:
If we raise the iteration count from 100,000 to 10,000,000, the results are as follows:
The bottom line is that there are always tradeoffs 😉 As this topic doesn't refer to an actionable ClearScript issue, we've converted it to a discussion. Please feel free to send additional thoughts or findings our way. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Parallel ForEach improves the efficiency of for loops. Following code works now on Topaz. var engine = new TopazEngine();
engine.AddType(typeof(Console), "Console");
topazEngine.AddType(typeof(Parallel), "Parallel");
engine.ExecuteScript(@"
var sharedVariable = 0
function f1(i) {
sharedVariable = i
}
Parallel.For(0, 100000 , f1)
Console.WriteLine(`Final value: {sharedVariable}`);
"); |
Beta Was this translation helpful? Give feedback.
-
Latest benchmark results for script engines: 1M for loop with no host interaction: | Method | Mean | Error | StdDev |
|----------------- |-----------:|-----------:|-----------:|
| RunV8Engine | 6.245 ms | 0.0423 ms | 0.0396 ms |
| RunParallelTopaz | 125.584 ms | 2.4922 ms | 5.2022 ms |
| RunTopaz | 523.444 ms | 10.3078 ms | 9.6419 ms |
| RunJint | 882.752 ms | 13.7271 ms | 10.7172 ms | 1M manipulations on arbitrary .NET objects | Method | Mean | Error | StdDev |
|------------- |------------:|----------:|----------:|
| RunTopaz | 792.0 ms | 9.74 ms | 9.11 ms |
| RunJint | 896.6 ms | 7.78 ms | 7.28 ms |
| RunV8Engine | 30,598.6 ms | NA | NA | For more benchmarks see: https://github.com/koculu/topaz |
Beta Was this translation helpful? Give feedback.
-
I have written a JS engine in pure C# which supports multithreading.
Performance and memory consumption is far more better than Clearscript and good for server-side rendering.
https://github.com/koculu/topaz
Please take a look. I posted here for those who might be interested in.
It seems like marshaling to C++ is not a good way for .NET applications.
Beta Was this translation helpful? Give feedback.
All reactions