In this article I would like to give you some details towards next version (2.0) of the S# language and scripting runtime.
Version 2.x will be based on .NET 4.0 and will be supported separately of Version 1.x that is still built on the top of .NET 3.5. Both versions will have a set of common features powered by both .NET 3.5 and .NET 4.0 however version 2.x will introduce a set of brand new capabilities built on the top of .NET 4.0 only. The entire 2.x family will be backward compatible. There will be no breaking changes in the scripts and migration difficulties.
Performance
A lot of work is related to script execution performance. S# runtime is used in various reporting and visualization tools where execution time of large or repetitive blocks is very important. Version 2 provides tremendous improvements and optimizations in comparison to Version 1.0.
Here’s one of our comparison benchmarks for basic loops (execution results are given in milliseconds)
| Script | v.1 | v.2 | % |
| for (i = 0; i <= 100000; i++) { } | 48.7 | 26.7 | 182 |
| for (i = 0; i <= 100000; i = i + 1) { } | 63.84 | 41.38 | 154 |
| for (i = 0; i <= 100000; i++) { i.ToString(); } | 4129.5 | 227.06 | 1517 |
| a = [1,2,3]; x = 0; for (i = 0; i < 100000; i++) { x = a[1]; } | 1571.1 | 72.62 | 2164 |
| a = [1,2,3]; for (i = 0; i < 100000; i++) { a[0] = i; } | 2630.9 | 87.38 | 3011 |
| x = null; p = new Person(); for (i = 0; i < 100000; i++) { x = p["testme"]; } | 1242.8 | 75.56 | 1645 |
| x = null; p = new Person(); for (i = 0; i < 100000; i++) { p["name"] = "test"; } | 1322.8 | 82.2 | 1609 |
| for (i = 0; i <= 100000; i++) { i.ToString(null); } | 3257.8 | 773.06 | 421.4 |
As you can see the performance improvements for loops, method calls and array manipulations range from 200% for 3000% and this is not the complete list.
Here’s the graphical charts for the first 50 calls of each script benchmark (vertical axis is given in milliseconds):
All the tests were performed on Windows 7 Ultimate ( x64), Intel Core 2 Duo T9400, 2.5GHz, 4GB RAM
Dynamics
I’m glad to announce that S# 2.0 will support “dynamic” objects powered by .NET 4.0 and its DLR (Dynamic Language Runtime) part. There will be a new type alias called “dynamic” that will allow you creating objects on the fly similar to the following sample:
| person = new dynamic(); person.Name = “John Doe”; person.Age = 40; |
This should significantly improve scripting experience an reduce efforts required to perform complex reporting or visualization scripts as types can be created dynamically during script execution instead of creating custom types and registering them within the runtime host.
The performance of dynamic objects is also very important for us. For the moment object property access (both getting and setting property value) is much quicker than of plain CLR type:
Integration
You will get more samples related to S# integration with other technologies and products. Soon there will be a set of articles regarding new features in S# for WPF and Silverlight, Microsoft Office 2007/2010 etc.
S# framework will provide a new libraries targeting OpenXml SDK 2.0 reuse within the scripts. It will be possible getting and setting data for Microsoft Excel 2010 document by accessing cells in scripts similar to the following way:
| workbook = new Workbook(“Book1.xslx”); workbook.Sheet1.A1 = “Hello world”; workbook.Sheet1.A2 = 100; workbook.Sheet1.B1 = workbook.Sheet1.A2 + 200; |
More news are on the way…
This is great news when can we expect version 2 to be released?
Ezra, soon as .net 4.0 goes RTM. Silverlight 4 will be released soon as SL4 goes RTM. Hopefully late this month.
Will S# 2.0 support either Silverlight 3 or Silverlight 4?
We are going to support Silverligt 4 for version 2.0.
Hi, is S# the same language Petro Protsyk developed under the name of Script.Net? Or is it a new project? I’ve been using Script.Net for a BPM engine, but had to look for something else as Script.Net wasn’t being developed very actively.
Yes you are right, this is the former Script.Net being developed very actively these days
That’s nice, I’d be happy to have it again, but this time in production quality. Are you selling it or giving away? Can I give it a try?
Please refer to this site for more details.
Dennis, I downloaded S# runtime from that site but this version behaves just like the last Script.Net I had. I mean, it’s quite buggy (the same bugs) and doesn’t provide good error information.
Bug examples:
- S# is unable to properly resolve overloaded methods, try Console.WriteLine with format specifiers
- When trying to reuse compiled scripts I get very strange behavior – despite assigning a new context to Script on each execution it behaves as if it were run in the same, first context each time
PS what happened to Mutants? (mutantic framework)
Mutants are being deprecated in favor of “dynamic” objects support we are working on at the moment. Does it make sense?
Yes, perfectly – that’s much better that developing your own dynamic object. Could you please tell me how to deal with precompiled scripts? I need to evaluate the same script expressions over and over, specifying different input variables each time. I wanted to precompile these expressions with Script.Compile and eval the compiled form – but as I have written above, can’t do it because the compiled script seems to be bound to initial context and evaluating the code in different context doesn’t work. Is there some pattern for that? If so, is it multithreaded?
And second question – exception stack trace from S# contains some strange characters, is it a result of obfuscation?
I’ve just created a group for S# related communication here. Could you please post all the questions and issues you come across so that me or Petro could help you resolving them shortly? Thanks in advance.
Can I use S# to create a custom script language? In other words I want to override the current script and define a syntax similar to the following:
Labels can be any text. There are about 8 custom operations which I could implement via IInvokable extensions.
I’m afraid not.
Ideal for quickly enabling scripting in an application. The C# syntax is a great help. No need to learn new and esoteric syntaxes. Great job. Thanks a million for this lifesaver.