All Ideas

Idea Details

Post an Idea
330  Points
Open
Idea has been posted. Give it an upvote or downvote.

Don't count garbage collection time in a request's CPU time

Reports & Dashboards

It has been reported on multiple occasions (e.g. http://salesforce.stackexchange.com/questions/18244/how-does-sf-calculate-the-cpu-time) that the CPU time reported for the same task can have significant variations, leading to lack of confidence whether a complex request will be able to consistently execute, or will fail over the CPU time limit.

I have noticed that calls to Limits.getHeapSize() can significantly increase a request's CPU usage. I assume that in an attempt for Limits.getHeapSize() to accurately report the heap size, garbage collection is run before returning a result. This assumption is consistent with the variation in both wall clock and CPU times. I.e. running two requests that do/don't call Limits.getHeapSize() but are otherwise identical, will take consistently different time to execute, measured by both stopwatch and Limits.getCpuTime().

This idea is about excluding garbage collection time from a request's CPU time, either explicitly invoked using Limits.getHeapSize(), or that is occurring automatically.

Doing that would provide more consistent results as measured by Limits.getCpuTime() and more confidence for developers that complex requests will be able to execute in development and production environments.

Garbage collection will happen in the underlying framework anyway, so accounting those hardly controllable events into a user request's CPU time is also not quite fair.

Merge Idea · Flag

Latest Comment from Salesforce

  • Josh Kaplan - 4 years ago

    It's unfortunately very difficult to separate this out. It would require some fundamental changes which would require significant restructuring to ensure that the multi-tenant platform still worked securely. In brief, it can't happen.

    getHeapSize will do an actual heap walk, which is a very expensive operation. Doing this during your apex execution will cause your CPU time to go up significantly. This will be true, independent of garbage collection.

    Garbage collection occurs on a very small percentage of threads. It will usually happen on a non-Apex thread, so the percentage of Apex transactions which experience a garbage collection is miniscule.
  • Upvotes
  • Downvotes

Ideas

Apps

from AppExchange

Questions

Help us to keep IdeaExchange clean by pointing out overlapping ideas. We'll investigate your suggestion and merge the ideas if it makes sense.



 

 

Thanks for your merge suggestion. We will review it shortly and merge the ideas if applicable.

Salesforce takes abuse situations very seriously. Examples of abuse include but are not limited to posting of offensive language or fraudulent statements. To help us process your request as quickly as possible, please fill out the form below describing the situation. For privacy and security reasons, the final outcome of an abuse case may not be revealed to the person who reported it.


 

Thank you for your feedback. We take abuse seriously and will investigate this issue and take appropriate action.