Sue Hernandez's SharePoint Blog

SharePoint and Related Stuff

Category Archives: LINQ

CAML vs LINQ to SharePoint 2010 – Performance

Summary

LINQ to SharePoint is really cool.  There’s lots of things you can do with it that you can’t do with CAML alone.  It’s much easier to read, to work with, to maintain, and because of the strongly typed objects, you find more of your bugs at compile time than at run time like you have to with CAML.

However, let me just say LINQ to SharePoint performance STINKS big time when you’re doing relatively simple comparisons that you could just as easily do in straight CAML.

My Test Case

My test case is a program that reads in information from 2 different stored procedures in SQL, separates out the data, loads them in to 4 SharePoint Lists, and looks for invalid corresponding data in another SharePoint list.  Basically 1 list is a master Valid Codes list, 1 list is a master Invalid Codes list, and the other 2 lists are distinct lists of categories and departments that relate to those codes, coming from the denormalized SQL queries.  Basically you first put all the valid codes in to the valid list, then you go through the invalid codes and see if there are matching codes in the valid codes list, and if so delete them, then check for corresponding data in another SharePoint list that has those code values in it, then put the invalid code in the invalid list.

The results

Running the program using straight CAML queries and no LINQ took 3 hours 11 minutes.

Running the program using all LINQ to SharePoint and no CAML took 9 hours 2 minutes.

 

I’m really bummed, I liked LINQ.  Now I’m not so sure.