In working on my little photo editing app for WP7 I had a function that was running crazy slow.
The method in question had a loop that ran 480,000 times over the pixels in a test image. Inside this method I called out to a helper function to perform some math on the colors in the pixel.
The function ran way slower than similar methods that had all of their code inlined. This was especially noticeable on the phone itself. In the emulator, it was slow but bearable. On the phone, it was unusable for me. I know that method calls have some overhead, but this seemed a bit much.
I moved the entire loop into the helper function so there would be only one call. Things sped up by about 4x; Guess that’ll teach me. It works much better on the phone now. After some additional performance tuning of my math, it should be nice and snappy!
Lesson: Don’t make method calls during long running loops if you can avoid them. They are too slow.