I have a webpage that is taking way too long and need to optimize it. Because uninformed optimizing is the devil, I need to know what exactly is holding me down. A quick glance showed me that it is probably a LINQ to SQL query that is most likely causing the trouble.
What are techniques of pinning the performance problem in this case? Are there specific things you experienced that LINQ to SQL is not that good at and thus should be avoided?
If needed, I can give more detail on the code that builds the query.
You can use a LINQ to SQL debug visualizer; Scott Guthrie has a nice blogpost about this, LINQ to SQL Debug Visualizer.
Another application that can give you valuable information is the SQL Profiler. Check the introduction Introduction to SQL Profiler, it should get you started.
I’ve had a couple of performace issues. I added a whole lot of TimeSpan objects with the current time before and after every LINQ statement. I added a few break points to see what the differences where between all this TimeSpans. In the Watch window you can calculate the difference on the fly and immediately see where the painpoints are. In my case it turned out to be a call to an extension method called at the wrong time.
Also, the InsertOnSubmit and the SubmitChanges can cause a delay. Because my client shouldn’t have to wait on that, I placed the inserts on a different thread.