0

I've been working on a grid-based game and ran into a performance problem. Iterating over thousands of grid nodes caused noticeable lag and the profiler showed that my property getters we're the source of all evil.

 public int xSize { get; set; } // 130 ms
 public int xSize; // 30 ms

The profiler reported 130 ms for all calls of the backing field via get_xSize. I changed it to a public field and the time went down to 30 ms. That's more than 20% speed improvement only because of a simple getter.

How can this be? I thought that property getters are inlined by the JIT, but apparently this is not true, at least when testing with the Profiler in the Unity editor. Or might the test scenario be the problem and they are inlined in non-debug build?

Xarbrough
  • 1,393
  • 13
  • 23
  • You should try to profile the release build. You could also try to dis-assemble the release build and see if the properties get inlined. But, without having looked at it myself, it seems fitting that the debug version would be less optimized. – Mike Dinescu Jun 05 '16 at 18:21
  • I don't think methods are inlined in debug builds: http://stackoverflow.com/a/4045073/4077294 Not sure though. – James Ko Jun 05 '16 at 18:23

0 Answers0