Avoid unnecessary processing

You don't want to spend a lot of CPU cycles doing work that isn't needed. Here are some ways to avoid that:

  • Validate early. Make sure you have all the data you need in the correct form before spending resources processing the data. If you're going to fail, fail early.
  • Check whether the visitor is still connected before doing expensive processing. You can do this by checking Response.IsClientConnected.
  • Check Page.IsPostBack, so that you won't regenerate data that you already have in ViewState.

Get ASP.NET Site Performance Secrets now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.