Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How scalable is LINQ? [closed]

Recent conversations with colleagues have produced varying points of view on this matter. What say you, SO members?

I know, even the concept of scalability can be taken in so many different ways and contexts, but that was part of the discussion when this came up. Everyone seemed to have a different take on what scalability really means. I'm curious to see the varying takes here as well. In fact, I posted a question just for that concept.

like image 858
Kilhoffer Avatar asked Oct 18 '08 00:10

Kilhoffer


2 Answers

I would guess that the best way to check is by writing benchmarks, but in my opinion LINQ has the possibility for optimizations that hand-writing similar code does not. I don't know how well it takes advantage of those yet.

LINQ lets you express what you want, not how to generate it. One obvious advantage is that LINQ is automatically parallelizable (see PLINQ).

Another advantage to LINQ is that it is lazy, so you can perform calculations, drawing from the collection as needed. You could hand-code an equivalent, but it may be much easier to get right in LINQ.

like image 174
Lou Franco Avatar answered Oct 17 '22 10:10

Lou Franco


In tests we did, LINQ to objects (ForEach) was about 2x times slower then foreach loop.

LINQ to SQL (MS SQL Database) is almost 10x slower than direct query using data reader, using most of the time creating SQL from expression tree (so, you'll be CPU bound and Database will be idling) To avoid this, you must use compiled queries.

See this for more. Most info in the post is still valid with .NET 3.5 SP1.

like image 38
bh213 Avatar answered Oct 17 '22 11:10

bh213