Cecil performance issues 2
At the beginning, Cecil was written to be an assembly manipulation library. The initial goal was to be able to read assemblies without loading them in an AppDomain, and also, to expose more that what .net 1.1 provided.
I implemented the writing parts of Cecil during my first Summer of Code, and barely touched it after, at it turns out it was working.
But this summer, two great hackers, Jeroen, author or IKVM, and Rolf, our VB 8 compiler author, decided that they gave enough blood and sweat to work around System.Reflection.Emit issues, and prototyped a version of their project based on Cecil instead.
If Rolf decided to go the full Cecil way, and replaced the usage of System.Reflection and System.Reflection.Emit (his branch is available), Jeroen decided to write a layer on top of Cecil that mimics the System.Reflection.Emit API.
Both wrote a sum-up about their findings, here for Jeroen, and there for Rolf. And both came to the conclusion that Cecil performs a lot less well that System.Reflection.Emit, both in terms of speed and memory consumption.
Rolf also uses the delay loading branch of Cecil, created by Mainsoft for their CIL to Java bytecode translator.
So the point is that Cecil uses too much memory, and is not fast enough in those scenarios, while it performs better in the reading only or reading + manipulating.
The good news is that, thanks to those hackers, we have now two amazing test cases to work on and to optimize. I’ve also started a few weeks ago, as a night hack, a refactoring of Cecil, that removes the intermediate structures that the current version of Cecil uses to read and write assemblies. If that makes reading and writing a little bit more complicated, it should also save a lot of memory.
And who knows, maybe one day, when Cecil will be optimized properly, and that the SRE on top of Cecil layer will be sufficient, it will require only a couple of changes to base mcs on Cecil.
Anyway, kudos to those hackers, let see what I can do to catch up.
We’ll let you know!
System.Scripting 6
Two days ago, I was sharing what I was foreseeing for C# 4 and .net 4, and the integration with the DLR.
Turns out that today, by reading this post, my eye was caught by the namespace I was thinking about: System.Scripting.
But this post is about the beta 4 of IronPython 2, that hasn’t been released yet. But heh, it’s easy to forget that latest IronPython code can be downloaded from CodePlex’s TFS.
And it indeed turns out, that in the latest revision, Microsoft.Scripting.Core namespace has been renamed to System.Scripting, and that the DLR AST has been merged into System.Linq.Expressions.
So yeah, I guess we can safely admit that C# 4 will have statements support inside expression trees.
And that .net 4 will contain very cute features for dynamically generating programs, without resorting to emitting plain IL, simply using the DLR, contained in a new assembly (or namespace, if they move some to parts to System.Core), System.Scripting.
.net 4, C# 4, and the DLR
UPDATE: turns out that there’s some true in those previsions, a small follow up.
I’ve been thinking a bit about the discussion in this video, about the future of C#, and specifically about its next version. If nothing is said clearly and loudly, as they’re most probably waiting for the PDC, you can still get a glimpse of what C# 4 and .net 4 will get as new features.
I’m mostly interested in one aspect of those new features. It’s the possible integration of the DLR inside the framework, and in the C# language.
The DLR, as we used to have it in IronPython, has been split into two separate assemblies, Microsoft.Scripting, and Microsoft.Scripting.Core a few months ago.
Microsoft.Scripting.Core is probably the part that will make it into the framework. It’s the part that contains a generalist AST, a compiler for this AST, using both LCG and traditional SRE for the debug scenarios. It also comes with a fast dynamic call site implementation, and an hosting API. So are we going to have a new System.Scripting assembly?
An interesting change in the DLR, is the naming of the AST factory and nodes. I’ve spent the last months working on LINQ and the LINQ compiler in Mono, and comparing the LINQ expression AST with the DLR AST is an interesting thing to do.
The DLR AST is now basically the LINQ expression AST, with statements added. And it looks like the current DLR AST has been tinkered around what has been already shipped inside .net 3.5 in the namespace System.Linq.Expressions.
Here’s a small example. In System.Linq.Expressions, pretty much all node from the AST extends the type Expression. Each Expression has a NodeType property, of type ExpressionType.
And you can find the same thing now in the DLR, but with some stuff added.
public enum ExpressionType {
// some traditional expressions
Add,
AddChecked,
// ...
Call,
// ...
IfStatement,
SwitchStatement,
// ...
}
So for the DLR, a statement is an expression. It makes kind of sense for a dynamic language you’ll tell me, but it looks a bit weird to be implemented this way.
Anyway, C# 3 already has a way to create expression trees to support some basic meta programming features, I guess we can only wonder if C# 4 will extend the meta programming features to support not only expressions but also statements, using the DLR tree.
I have no idea how they’ll deal with the fact that the existing stuff is in System.Linq.Expressions. Are they going to obsolete the whole namespace, and redirect everything to a possible System.Scripting.Ast (sounds less likely)? Are they moving the DLR AST to System.Linq.Expressions (sounds more likely)? Who knows? Not me (I’ve never lost control).
Interesting speculations anyway :)
So for now, the only change I can foresee for C# 4, is that you’ll be able to get full code blocks instead of only expressions when asking for an Expression of T.
But here’s another interesting one we can have a glimpse here, is duck typing support based the DLR.
At the language level, it’s difficult to say if they’re going to rely
- on a dynamic code block, like the example shows in this blog entry,
- on a custom marker type,
- on another syntax for message passing to dynamic objects,
All in all, it looks like C# 4 will have some nifty stuff, let’s wait for the PDC.
Ohloh Journal
I’ve recently noticed that ohloh now allows you to publish a journal, made of short entries (less than 400 characters).
It feels more specialized than twitter, and pretty useful to log short updates on what I am hacking on, or short news for a project. For instance, Sébastien already started using it to publish short news about Gendarme.
That looks pretty nice to me, let see what ends up in my ohloh journal.




