Search code examples
asp.netexceptionpremature-optimization

Should i use HttpResponse.End() for a fast webapp?


HttpResponse.End() seems to throw an exception according to msdn. Right now i have the choice of returning a value to say end thread (it only goes 2 functions deep) or i can call end().

I know that throwing exceptions is significantly slower (read the comment for a C#/.NET test) so if i want a fast webapp should i consider not calling it when it is trivially easy to not call it?

-edit- I do have a function call in certain functions and in the constructor in classes to ensure the user is logged in. So i call HttpResponse.End() in enough places although hopefully in regular site usage it doesn't occur too often.


Solution

  • Just use Response.End. Write your code for maintainability before you write it for performance.

    Besides, the performance measure that matters for web apps is scalability. That is, you should not be asking "how fast can I process this single request", but "how many requests can I process at the same time?".

    Exceptions do not affect your scalability, and in the grand scheme of things, an extra couple of microseconds on a single request is nothing: remember it'll be at least 50 milliseconds in network roundtrip: another 100 microseconds is noise.