Microsoft Developer Network > Forums Home > Data Platform Development (Pre-release) Forums > ADO.NET Entity Framework and LINQ to Entities (Pre-Release) > snapshot based changing tracking faster then notification based for smaller model.
Ask a questionAsk a question
 

Questionsnapshot based changing tracking faster then notification based for smaller model.

  • Wednesday, November 04, 2009 7:12 PMzeeshan hirani Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    i find that snapshot based change tracking for pure poco model is faster then poco that uses change tracking proxy.

    public class Account
    {
        public virtual int AccountId { get; set; }
        public virtual string Name { get; set; }
        public virtual decimal Balance { get; set; }
        public virtual ICollection<Payment> Payments { get; set; }

    }
    public class Payment
    {
        public virtual int PaymentId { get; set; }
        public virtual string PaidTo { get; set; }
        public virtual decimal Paid { get; set; }
        public virtual int AccountId { get; set; }
    }

    //inserting
    var watch = new Stopwatch();
    watch.Start();
    using (var db = new POCOContext())
    {
        for (int i = 0; i < 5000; i++)
        {
            var account = db.CreateObject<Account>();
            account.Name = "test";
            account.Balance = 5000;
            account.Payments.Add(new Payment { PaidTo = "test", Paid = 5 });
            db.Accounts.AddObject(account);
        }
        db.SaveChanges();
    }
    watch.Stop();
    Console.WriteLine("Total Time for Insert:{0}",watch.Elapsed.TotalSeconds);

    //reading proxy objects
    using (var db = new POCOContext())
    {
        watch.Restart();
        var accounts = db.Accounts.Include("Payments").ToList();
        watch.Stop();
        Console.WriteLine("Time to read proxy objects:{0}",watch.Elapsed.TotalSeconds);

        //updating proxy objects.
        watch.Restart();
        foreach (var account in accounts)
        {
            account.Balance += 10;
            account.Payments.First().Paid += 1;
        }
        db.SaveChanges();
        watch.Stop();
        Console.WriteLine("Updating objects took:{0}",watch.Elapsed.TotalSeconds);
    }

    Now to run the same example with pure poco, i removed all the virtuals and change creation of account to as follows.
    var account = new Account { Payments = new HashSet<Payment>() };

    these are some of the averages i get.

    change tracking proxy.

     

    Insert

    Read

    Update

    4.28

    .507

    3.13

    4.27

    .506

    2.82

    4.26

    .506

    2.71

    4.30

    .501

    2.75

    4.14

    .507

    3.19

    4.23

    .515

    2.76

    4.26

    .508

    3.07

    Average

    4.24

    .507

    2.91



    Pure POCO

     

    Insert

    Read

    Update

    4.15

    .447

    2.86

    4.25

    .400

    2.81

    4.17

    .394

    2.90

    4.28

    .404

    2.87

    4.12

    .407

    2.90

    4.10

    .390

    3.07

    4.10

    .402

    2.82

    Average

    4.16

    .447

    2.89


    It looks like insert, and reads are definately slower but updates are pretty much same. that's with inserting 5000 records with a single payment. I would think snap gets expensive when the model is complicated with lots of associations

    Zeeshan Hirani