Wednesday, March 18, 2009


I was speaking the other day about the C# JIT and how it sucks sometimes... well, heres some real code to prove the point...

            m_ArrayAccess[0].m_Pos.Y = 2.0f;
00000022 lea edx,[ecx+8]
00000025 cmp byte ptr [edx],al
00000027 mov dword ptr [edx+4],40000000h
m_ArrayAccess[0].m_Pos.Z = 3.0f;
0000002e lea edx,[ecx+8]
00000031 cmp ecx,dword ptr [edx]
00000033 cmp byte ptr [edx],al
00000035 mov dword ptr [edx+8],40400000h
m_ArrayAccess[0].m_Pos.W = 4.25f;
0000003c lea edx,[ecx+8]
0000003f cmp ecx,dword ptr [edx]
00000041 cmp byte ptr [edx],al
00000043 mov dword ptr [edx+0Ch],40880000h

As you can see it not only continually reloads the base address of the array+type, but appears to insert pointless CMP instructions all over the place. The only reason I can figure for this is to attempt to prefetch the destination; however since its about to access it on the next instruction, this is pointless - Not only that but since its sequential chances are its in the cache alrady! And even is by some mirricle that it DID matter, why the hell is it doing it TWICE!!!

Man I find that annoying....


Jim said...

Heres a hint - C# is proprietary. I can bet you that Microsoft is planning on selling a dumbed-down version of it's JIT and C# compiler sometime in the future.

And if you want performance you'll have to pay out the ass for a version that doesn't intentionally produce bloat-ware.

Mark my words...

Mike said...

Actually... It's not. The JIT is open source and supported by Microsoft. This is why MONO manages to exist at all.

Microsoft spend quite a bit of time/effort on the JIT, and are actually open to suggestions - although because of project planning and release dates etc. they can take some time to make it in.

Mono on the other hand moves much quicker, and has introduced the likes of SIMD way before Microsoft (who do intend to add support it).

Microsoft will probably never sell their JIT, mainly because anyone wanting a free JIT can use MONO (as mono on the PS3 and iPhone testify to).

The Microsoft JIT is bloody annoying at times, but the good thing about it is that you don't have to release a new version to get a speed up, every time it loads and runs, it gets faster all on it's own!