autoeventwireup performance cost

后端 未结 4 1161
情书的邮戳
情书的邮戳 2021-01-12 10:35

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 pen

相关标签:
4条回答
  • 2021-01-12 11:00

    The performance difference is negligible.

    0 讨论(0)
  • 2021-01-12 11:02

    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.

    0 讨论(0)
  • 2021-01-12 11:10

    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.

    0 讨论(0)
  • 2021-01-12 11:23

    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.

    0 讨论(0)
提交回复
热议问题