[Mono-list] Performance issue

Serge serge@wildwestsoftware.com
Tue, 4 Sep 2001 21:47:42 +0400

> * Range checking: the runtime will detect invalid array access
>           by checking every time the range of the array.

Sometimes this could be eliminated by unrolling the loop that accesses the
array (this is true in the current MS implementation).
Some code in Mono's System.Security.Cryptography (MD5 stuff) uses this
Here is the original code on which the above is based -
There are C# (optimized and not-optimized), C++ and Java implementations.
Generally this optimized C# code runs as fast as C++ implementation (with
the same optimization applied).
Those who's fluent in x86 Assembly may use ngen tool to produce the native
image (essentialy off-line JIT) and see what's going on ;-)
Basically for urolled loop JIT-produced code performs bounds checks only
during the first pass, it caches the values locally (on the stack), and uses
"cached" values then.
Not sure whether this optimisation is applicable to your code though. And
it's quite possible that some other JIT could perform such optimisation
itself (it's quite clumsy to do it by-hand).
Also, if your array is an instance variable make a local reference to it
before accessing - this will improve speed.
And lastly - if you're just moving memory blocks, use Buffer.BlockCopy