[Mono-devel-list] First CIL Regex performance result

Varga Zoltan vargaz at freemail.hu
Fri Mar 5 11:27:46 EST 2004


   I think the main problem here is the Checkpoint and Backtrace
functions in CILCompiler.cs:

                private unsafe void Checkpoint (char*
scan_ptr) {
                        mark_start = mark_end;

                        if(CheckpointStack == null)
                                CheckpointStack = new Stack();

CheckpointNode(mark_start, scan_ptr));

This function is called approx 6 million times during the
regex test you
posted. Since CheckpointNode is a valuetype which is passed to 
Stack.Push, it needs to be boxed and thus a new object is
Object allocation and garbage collection is rather slow on
the mono
runtime. The original interpreter do not use a stack, so it
does not
suffer from this problem. 
Also, not all Checkpoint calls have a matching Backtrace
call, so the
stack grows to about 170000 elems by the end of the test.
Having a
growing 170000 element array in memory is not good either.
Checkpoint and Backtrace are called using the callvirt
instruction, which
might prevent the JIT from inlining them.

So my advice is: make the Checkpoint and Backtrace calls
similar to
the ones used in the interpreter. Instead of a stack, the
etc. variables might be stored in local variables inside the
Scan method,
as done in the interpreter. 


More information about the Mono-devel-list mailing list