Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I learn enough about CLR to make educated guesses about performance problems?
    primarykey
    data
    text
    <p>Yes, I <em>am</em> using a profiler (ANTS). But at the micro-level it cannot tell you how to fix your problem. And I'm at a microoptimization stage right now. For example, I was profiling this:</p> <pre><code>for (int x = 0; x &lt; Width; x++) { for (int y = 0; y &lt; Height; y++) { packedCells.Add(Data[x, y].HasCar); packedCells.Add(Data[x, y].RoadState); packedCells.Add(Data[x, y].Population); } } </code></pre> <p>ANTS showed that the y-loop-line was taking a lot of time. I thought it was because it has to constantly call the Height getter. So I created a local <code>int height = Height;</code> before the loops, and made the inner loop check for <code>y &lt; height</code>. That actually made the performance worse! ANTS now told me the x-loop-line was a problem. Huh? That's supposed to be insignificant, it's the outer loop!</p> <p>Eventually I had a revelation - maybe using a property for the outer-loop-bound and a local for the inner-loop-bound made CLR jump often between a "locals" cache and a "this-pointer" cache (I'm used to thinking in terms of CPU cache). So I made a local for Width as well, and that fixed it.</p> <p>From there, it was clear that I should make a local for Data as well - even though Data was not even a <em>property</em> (it was a field). And indeed that bought me some more performance.</p> <p>Bafflingly, though, reordering the x and y loops (to improve cache usage) made zero difference, even though the array is huge (3000x3000).</p> <p>Now, I want to learn <em>why</em> the stuff I did improved the performance. <strong>What book do you suggest I read?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload