Jump to navigation

Poupou's Corner of the Web

Looking for perfect security? Try a wireless brick.
Otherwise you may find some unperfect stuff here...

Weblog

Oops, I did it again

Google Summer of Code 2008 has taken another step forward and published the list of projects they will be funding this summer. I'm glad that Nestor will be back with us to work (well he never left but I'm still glad) on Gendarme again this year. Speaking of Nestor, he's the great mind behind the Gendarme Rule Day idea.

Reminder: this is next Saturday (April 26th). Don't miss it!

So no one applied on the optimization projects but like I said there is a lot of things do to and, best of all, results are quickly visible. In fact I had already spotted a nice candidate, inside Cecil, last time: Mono.Cecil.Cil.OpCode but decided, at the time, to wait for a few, or a lone, candidate(s). GSoC proposals ended and I decided to give it a go myself (already two weeks ago). Again I created a base line (using the same configuration as before). Total memory required: 796289 KB.

Then I applied the same tricks as S.R.E.OpCode use (inside corlib): keep all enums into bytes and use the properties to typecast the byte back into an enum at runtime (i.e. no impact on API). The structure went from it's original 36 bytes, which is way too large for a structure (which is also why I, well Gendarme, spotted it) to 8 bytes. Total memory went down to 731768 KB (44% less memory on Mono.Cecil.Cil.Instruction allocations, 8% less total).

I also played with a smaller version: 2 bytes for the OpCode and everything else inside tables. I did not expect miracles here since it's too small an amount to be allocated nicely (e.g. alignment). Total memory went down to 722565 KB (50% less memory on Mono.Cecil.Cil.Instruction allocations, 9% less total). However it's performance was twice as slow (using tables againt the casts of the previous version) so this was not the version selected to go in SVN.

When you keep looking at logs, even old ones, you eventually see new things in them. I knew most memory was inside Hashtable, tried to minimize and reuse them but I forgot, well didn't see, something: the biggest ones are temporary and consist of the offset and Instruction for the IL of each method and the second biggest are elsewhere but identical. The debugging symbols assemblies, Mono.Cecil.[Mdb|Pdb].dll, were doing the same, temporary hashtables, to help place their values.

Simply sharing the same hashtable between them brings down total memory from (new base line) 722970 KB to 647636 KB, a bit over 10% reduction.

It actually took a bit more time (but not much and with fewer changes) than my previous attempt but I still got (more than) another 15% decrease in Cecil memory usage (at least if you're using the symbol helpers). Anyway enough Cecil hacking for now, next weekend is on Gendarme (Rule Day) and it's time I get my good friend JB hacking (more) on it ;-)


4/21/2008 20:53:26 | Comments

The views expressed on this website/weblog are mine alone and do not necessarily reflect the views of my employer.