views:

591

answers:

4

I have been looking at improving my asp.net page performance, is it worth changing autoeventwireup from true to false and adding the event handlers or is the performance penalty very small?

This is an asp.net 2.0 project.

+1  A: 

The performance difference is negligible.

Dave Ward
what evidence do you have for this claim?
Jon
burden of proof is on the optimizor
Dustin Getz
A: 

The performance is 0, because once wired up (once your application is compiled in memory), it never has to do it again. What I mean by that is, the ASP.NET framework isn't constantly itterating through every method by name to see if it should be wired up.

But, I strongly suggest you turn it off, because it usually causes issues of double page loads or whatever (if you wire up an event yourself, but due to naming it a certain way, ASP.NET wires it up too).

That's a feature that I wish was defaulted to off.

Timothy Khouri
+4  A: 

The wireup isn't done at compile-time. It's done at runtime. As described in this article:

http://odetocode.com/Blogs/scott/archive/2006/02/16/2914.aspx

There IS a performance penalty because of the calls to CreateDelegate which must be made every time a page has been created. The performance hit is probably negligible, but it does exist.

Keltex
+2  A: 

From MSDN article.

Performance Tips and Tricks in .NET Applications

Avoid the Autoeventwireup Feature

Instead of relying on autoeventwireup, override the events from Page. For example, instead of writing a Page_Load() method, try overloading the public void OnLoad() method. This allows the run time from having to do a CreateDelegate() for every page.

Knowledge Base article:

How to use the AutoEventWireup attribute in an ASP.NET Web Form by using Visual C# .NET

When to avoid setting the value of the AutoEventWireup attribute to true

If performance is a key consideration, do not set the value of the AutoEventWireup attribute to true. The AutoEventWireup attribute requires the ASP.NET page framework to make a call to the CreateDelegate function for every ASP.NET Web Form page. Instead of using automatic hookup, you must manually override the events from the page.

Jon