CHUVASH.eu

CHunky Universe of Vigourous Astonishing SHarepoint :)

Set ObjectTrackingEnabled = false when reading

In LINQ 2 SP we work with a data context. By default a data context has the property ObjectTrackingEnabled = true. This property is crucial for all other operations in CRUD except Read. I performed a mini experiment. I created 20 000 items in my task list. Every seventh item contains “pärla”. Allright, here is what I found out:

2857 / 20 000 items
ObjectTrackingEnabled = true 07s.405ms
ObjectTrackingEnabled = false 01s.232ms

Sharepoint as a developer platformWith ObjectTrackingEnabled it takes 6 times more time to read the list items: whole 7,5 seconds. It would be a catastrophy if you would run this code to retrieve some items in your webpart which runs synchronously in the main thread.

The best SharePoint book from a developer perspective (SharePoint 2010 as a developer platform) explains ObjectTrackingEnabled:

Track Changes
The LINQ to SharePoint provider checks changes made in the database against its current state. This is
the default behavior. If you access the lists in a read-only manner, the tracking can be suppressed to
optimize performance:
ctx.ObjectTrackingEnabled = false;

Here is the code which I ran to get the results:

Console.WriteLine("Oppgaver, 20 000 items");
var sw = new Stopwatch();

Console.WriteLine("Retrieving items containing pärla");
Console.WriteLine("\n");
Console.WriteLine("**** ObjectTrackingEnabled=true (default) ****");
sw.Start();

using (var ctx = new OppgaverDataContext("http://takana/"))
{
	var tasks = ctx.Oppgaver.Where(t=> t.Title.Contains("pärla")).ToList();
	Console.WriteLine("\tcount: " + tasks.Count());
}

sw.Stop();

var elapsed = String.Format("{0:00}s:{1:000}ms", sw.Elapsed.Seconds, sw.Elapsed.Milliseconds);
Console.WriteLine("\ttime:\t" + elapsed);

sw = new Stopwatch();
Console.WriteLine("\n");
Console.WriteLine("**** ObjectTrackingEnabled=false ****");
sw.Start();

using (var ctx = new OppgaverDataContext("http://takana/") { ObjectTrackingEnabled = false })
{
	var tasks = ctx.Oppgaver.Where(t => t.Title.Contains("pärla")).ToList();
	Console.WriteLine("\tcount: " + tasks.Count());
}

sw.Stop();
elapsed = String.Format("{0:00}s:{1:000}ms", sw.Elapsed.Seconds, sw.Elapsed.Milliseconds);
Console.WriteLine("\ttime:\t" + elapsed);
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Вула Чăвашла

VulaCV - Чăвашла вулаттаракан сайт

Discovering SharePoint

And going crazy doing it

Bram de Jager - Coder, Speaker, Author

Office 365, SharePoint and Azure

SharePoint Dragons

Nikander & Margriet on SharePoint

Paul J. Swider - RealActivity

RealActivity is a specialized healthcare services and solution advisory firm.

Mai Omar Desouki - Avid SharePointer

Egyptian & Vodafoner - Senior SharePoint Consultant

Cameron Dwyer | Office 365, SharePoint, Outlook, OnePlace Solutions

Office 365, SharePoint, OnePlace Solutions & Life's Other Little Wonders

paul.tavares

Me and My doings!

Share SharePoint Points !

By Mohit Vashishtha

Jimmy Janlén "Den Scrummande Konsulten"

Erfarenheter, synpunkter och raljerande om Scrum från Jimmy Janlén

Aryan Nava

| Blockchain | Serverless Architecture | Microservices Architecture | DevOps | AWS Lambda | Teraform |

SPJoel

SharePoint for everyone

SharePointRyan

Ryan Dennis is a SharePoint Solution Architect with a passion for SharePoint and PowerShell

SharePoint 2020

The Vision for a Future of Clarity

Aharoni in Unicode

Treacle tarts for great justice

... And All That JS

JavaScript, Web Apps and SharePoint

blksthl

Mostly what I know about SharePoint - CommunicoCuspis

%d bloggers like this: