- Cost of Code
- CPU time Limit
- Benchmarking technique for Code
- Benchmarking technique for Declarative
Speaker : Purushottam Bhaigade
Date : Saturday, DEC 07, 2019 10:00 AM EST ( 8:30 PM IST)
- Script limit – Total number of line of Apex code executed
- Separate limits for each Managed Package (Aloha)
- Trigger Context – 200,000 lines
- Async (Batch & Future) – 1,000,000 lines
- Workflow, Process Builders, Formulas has no limits at all
What Changed after Winter’14 ?
Script Limit were changed to calculate CPU Time usage
Why Software Benchmarking is hard?
- Time measurement can’t trusted always, because system performance varies based on time of day and momentary load.
- Debug log cost CPU time
- You don’t have control on background operations like garbage collection
- Result might change with each patch release
- Assignment from static field reference is 20x time slower than variable assignment
- Assignment from dynamic field reference is 30x time slower than static assignment
- Use temporary variable instead of referencing a field multiple times!
- The cost of sending email notifications via Workflows can add up 15 ms/email (10 field merge
template). Ultimately that is 3 seconds for 200 records !
- What is Alternative then? Create task for user – only 0.5 ms per record (tested with basic formula workflow)
- Validation Rules : Each validation formula function takes about 30 microseconds. Example : 10 validation rules, each with 10 functions, applied to 200 records = 600 ms
How to prevent this?
- Use Limits.getCPUTime() to find out you are getting into trouble, then either exit or go async if you are getting close
- Learn more advance architectures to detect reentrancy
- Try to use Platform event in your solution for Async operation
- Accept that you still may get the blame
Here is recording of session:-
Here is PPT of session:-Apex code Benchmarking from Amit Chaudhary
Please note that we have limit of 200 attendees that can join the online sessions. However, recording will be posted on our YouTube channel. Make sure to subscribe our YouTube channel to get notification for video upload.
Check our “Session in 2019” page for all upcoming and old sessions of 2019.
Sharing is Caring so Share with your friends
Salesforce Apex Hours