Optimizing LINQ Queries

LINQ Queries

Writing a highly scalable/responsive website takes a lot of work, which includes optimizing hosting infrastructure (multi-server, geo-dependent, content delivery networks etc.), page speed/JavaScript, and the actual website performance.

If a page on your website takes about 1 second to load, you have to admit, there’s something wrong with it. Of course, sometimes it’s rather difficult to achieve 20ms rendering time. However, in most cases, some basic code optimization tricks allow you to achieve acceptable 50-70ms to start with. This would be enough to serve the page to 50-100 concurrent users.

The algorithm of performance optimization is a simple as it gets:

  1. Find a "bottleneck" / non-optimal code
  2. Fix it
  3. Repeat Steps 1-2 until pleased with the result.

Finding bottlenecks is achievable by using performance profiles. You can use either the built-in CMS Page profiler, or one of the .NET profilers out there such as JetBrains dotTrace.

As to fixing bottlenecks, in most cases, the problem code is in the way you query/process data.

This article describes how LINQ works and on what conditions its execution time depends.

C1 CMS allows you to choose between two different ways of storing data: XML and SQL.