SingingEels : Development Community & Resource

Login

Articles

  • ADO.NET (2)
  • ASP.NET (31)
  • LINQ (4)
  • Security (2)
  • Silverlight (2)
  • SQL (7)
  • Standards (5)
  • WCF (1)

Syndication

  • Articles RSS
  • Blogs RSS

Contribute

  • Our Authors List
  • Member Sign-Up
  • Suggestions Box

My Bad Coding Habits, Thanks LINQ to SQL!

(Jun 05 2008 - 08:19:17 PM by Timothy Khouri) - [print blog post]

Don't Forget Performance!

I have to start off by saying that I'm not seriously blaming LINQ to SQL for my bad coding habits, but I will mention that due to all these great technologies that just do stuff for us, we sometimes forget to check for things like performance. Sometimes I take for granted that .NET is ultimately just running code that some mere mortal programmer wrote.

As a result, I just assume that anything that happens outside of *my* code will run at infinite speeds. So, the other day I was reprimanding (not really, but I was semi-lecturing) one of my senior developers for hitting the SQL server in a for loop. Now, to be fair, he's new to LINQ to SQL, and didn't realize that this...

foreach (Task t in myTasks) {
   if (t.BillingEntries.Count() > 0) {
       // this is just an example

   }
}

...was going back to the database over and over again :) Just for clarification, the "BillingEntries" property up there is linked from another SQL table.

It wasn't difficult to fix the problem. All we needed to do was get the "count" information in a single hit to the DB, store it in a dictionary, and use it in the for loop, instead of hitting the DB in the for loop.

Where I Had To Eat My Words

So, yesterday, as I was updating some styling on the site (SingingEels.com), I realized that some pages were taking a long time to load (from my local machine). A few pages were taking upward of 10 seconds each... and that's when I realized!

My web server and SQL server are physically next to each other (I think in Colorado, USA), but I live in Florida. So, when I was developing locally, and my web app hit my SQL server in a for loop... well, you get the idea.

Needless to say, I've since then been optimizing the site, and I've included a "server load time" number at the bottom of the site. The moral of the story is, don't forget to check your app for performance issues.

You must be logged in to add comments. If you have not already done so, you can create an account here. If you already are a member, you first need to login before you can comment.

Developer / Architect / Author

Blog Archives

  • August 2008 - (3)
  • July 2008 - (1)
  • June 2008 - (3)
  • May 2008 - (2)
  • April 2008 - (2)
  • March 2008 - (4)
  • February 2008 - (2)
  • December 2007 - (2)
  • November 2007 - (1)
  • October 2007 - (4)
  • September 2007 - (9)
  • August 2007 - (7)

Related Ads

SingingEels.com as of Aug 20 2008 - 08:57:43 PM - (0.0625)