[Mono-bugs] [Bug 80508][Nor] Changed - code quality regression for array init

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Mon Jan 15 10:04:51 EST 2007

Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by lupus at ximian.com.


--- shadow/80508	2007-01-15 07:47:57.000000000 -0500
+++ shadow/80508.tmp.5967	2007-01-15 10:04:51.000000000 -0500
@@ -126,6 +126,35 @@
 I think it is too expensive to call ArrayInit when e.g. array will be
 size of 300 and only 15 items will be constants and the rest of items
 are either 0 or non-constant expressions.
+------- Additional Comments From lupus at ximian.com  2007-01-15 10:04 -------
+There is no mananged/unmanaged transition cost in this case, because
+no transition happens (with my patch). The only cost is the call to
+memcpy() and for small sizes this can be removed as well. Consider
+a byte array with 4 elements: the JIT can just insert a single
+instruction to store an integer, so the best thing would be to always
+use the initialization call, but for sizes < 4 you can reasonably
+avoid it. My 10-20 suggestion was from a quick look at the issue,
+without measuring things.
+As for the partially initialized array, consider this: depending on
+the array element types, the memory cost of initialization (with full
+optimizations, even the ones we don't do yet) is from 5-6 to 16-20
+bytes (byte arrays to long arrays) of runtime writable memory.
+Using the initialization call the cost is 1-8 bytes of readonly memory
+mmapped from the file.
+Since writable memory is a more expensive resource than readonly
+memory, the factor of non constant use must be much higher than 50%.
+An int array of size 100 with only 20 constant elements would take
+about 20*10=200 bytes of initialization code in writable memory (the
+actual number with default optimizations is closer to 300 bytes,
+though). On the other hand this would be 400 bytes of mmapped memory,
+which is cheap. We need to consider the cost of useless copying (which
+will be offset by removing the GC initialization, though), but in the
+overall picture, it will still be better or close in performance and
+resource usage. So I suggest a non-constant expression factor closer
+to 80% to decide to switch to hand-rolled initialization.

More information about the mono-bugs mailing list