1 Reply Latest reply on Mar 20, 2015 8:51 PM by Mark Nongkhlaw

    Performance advantage of transactions

    Jon Tara

      This was an aside in an unrelated post, and I felt it deserved it's own!

       

      Did you know that using transactions both protects against partial updates, as well as bringing a HUGE performance boost? Make sure to use transactions whenever you create or modify a bunch of records. It's especially effective when seeding a database from e.g. some downloaded data. And also especially so when you are adding records to fixed-schema tables with a lot of indices.

       

      I did some simple experiments today inserting records into a narrow (few fields) (but heavily-indexed) table. Since I only inserted 200 records, it is probably not yet enough records to show the true difference, but... it certainly is significant!

       

      iPhone 5S

       

      Transaction: 150 mSec, or 0.75 mSec/record

      No Transaction: 3500mSec, or 17.5mSec/record

       

      Using a transaction was 23 times faster than not using a transaction.

       

      Note that Rhom always uses a transaction internally (you can nest them) but that internal transaction is only for whatever single call you make to Rhom.

       

      FWIW, times on OS X (iOS simulator):

       

      Transaction: 40mSec, or 0.2mSec/record

      No transaction: 980mSec, or 4.9 mSec/record

      24.5 times faster, so pretty consistent

       

      You can find the code I used here:

       

      Model monkey-patching how-to