32 or 64-bit?

Apr 25, 2010 at 7:13 PM

When the DLR delegates are dynamically compiled in memory, are they compiled as 32bit or 64bit? I'm having some weird issues with struct performance inside the DLR, when I do it in C# i get the same performance as the DLR if I use 32bit and a lot better if I use 64bit. This leads me to believe that the DLR compiles everything as 32bit? If it is 32 bit, is there any way to get it to be compiled as 64bit? Does .CompileToMethod instead of .Compile allow me to use 64bit? 

Maybe I'm miles off with this, but I couldn't find any other reason for the performance degradation.

Apr 25, 2010 at 7:23 PM
On Sun, Apr 25, 2010 at 8:13 PM, [email removed] wrote:
> When the DLR delegates are dynamically compiled in memory, are they compiled
> as 32bit or 64bit? I'm having some weird issues with struct performance
> inside the DLR, when I do it in C# i get the same performance as the DLR if
> I use 32bit and a lot better if I use 64bit. This leads me to believe that
> the DLR compiles everything as 32bit? If it is 32 bit, is there any way to
> get it to be compiled as 64bit? Does .CompileToMethod instead of .Compile
> allow me to use 64bit?

How could the JIT on x64 compiles 32 bit code in a 64bit process?

Anyway, I think that the difference you see can be explained by the
fact that .net x64's JIT has optimizations to allow inlining of method
calls with struct arguments, which the x86 JIT doesn't have, and also
by the fact that DynamicMethod are marked as not inlinable on .net (at
least that what they return as implementation flags, I can't say for
sure that the .net JIT doesn't inline them). But it sounds a plausible
explanation.

--
Jb Evain <jb@nurv.fr>
Apr 25, 2010 at 7:27 PM

To expand just a little on what Jb wrote, it is not possible to mix 32-bit and 64-bit user code in the same process (at least under Windows).

Apr 26, 2010 at 7:27 AM

DynamicMethods are compiled with the same JIT as other IL. Like Jb said, differences in inlining are the most likely culprit for why DynamicMethods would behave differently from other methods.

You might want to try playing around with the security rules on your calling/called assembly—you might have better luck with something like: SecurityRuleSet.Level1 + SecurityTransparent. (Sometimes the JIT won’t inline because it needs the stack frame for security checks).

In my experience the x86 and x64 JITs have quite different performance characteristics. A few of the differences I’ve hit: whether it will perform tail calls, the threshold for tracking locals, time to compile a method, how good the inlining is, and overall quality of the generated code.

- John