Relative performance of CRUD

In an application I have some Apex code that does quite a lot of computation and saves the results in several objects. If the results have been generated before, the code first deletes the existing objects. On adding some timing code, I was surprised at the distribution of the times, particularly how expensive the deletes are and how cheap the reads (selects) are.

Here is the data (values in milliseconds and dealing with a few dozen objects in each case) for a couple of variations:

The parts are:

  • Find: doing a SOQL select to identify the “ids” of the objects to delete
  • Delete: a single Apex “delete ids” call
  • Calculate: Apex “new” calls and various calculations to populate the objects
  • Insert: a single Apex  “insert newIds” call to insert the calculated objects

3 thoughts on “Relative performance of CRUD

  1. Neat-o! Did you track the execution times with the Limit class? I wonder if the delete takes so long because SF makes records ‘undeleteable’.. in which case they don’t really delete but simply move them aside.

  2. I tracked the times with a little timing class I wrote that just uses Datetime and has start/stop methods and accumulates the information. Not elegant. Is there already something similar in the platform?

  3. Pingback: My laptop is 300 times faster « Force 201 – Development

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s