Search code examples
asp.net-mvc-3linqlinq-to-sqlmvc-mini-profiler

Please explain this behaviour (is LINQ cached)?


I recently added the wonderful MiniProfiler package to my project and it helped me a lot to improve page render speed.

Now I notice the following. Every first request to a page takes a significant longer time in SQL than subsequent visits.

Here's an example:

First visit:

First visit

Second and later visits:

Second visit

Is this caused by some sort of caching in LINQ or on SQL Server? I'm using .NET 4 and LINQ-to-SQL with default settings in my dbml file.


Solution

  • There are a lot of things that can affect the performance of a first hit. The jitter might have to do some work, and various levels of caching might come into play.

    That said, SQL Server has very advanced caching features. It's not at all unusual for repeat queries against the server to be much faster than the initial query.