[SalesForce] Performance profiling best practices

Given that:

  • debug statements consume memory and cpu resources and thus skew performance measurements
  • developer console in profiling perspective shows just events that were logged
  • debug log size is severely limited
  • database inserts are not necessarily immediate

What best practices have you found when performance profiling code on Salesforce?

Best Answer

I think profiling is most useful when you are isolating small chunks of functionality. If you want to know whether it is faster to use List.isEmpty() or List.size() > 0, that sort of question is possible to answer definitively using profiling.

If you take a look at my LimitsProfiler tool, it may give you some ideas. I definitely won't go so far as to say best practice, but I have walked down a similar path and my experience may benefit you.

I profiled LimitsSnapshot.getInstance(), a method which caches all the information given to you by the Limits class. If memory serves, at the time I wrote it, I was able to cache millions of these snapshot instances within a one second interval.

So if you wanted to use my library, you ought to be able to manage a static List<LimitsSnapshot>, and then at the end you can save them, debug them, or whatever you wish.

Related Topic