Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide performance

  1. 1. Simple steps to improveperformance of ASP.NET Application Brij Bhushan Mishra
  2. 2. Agenda Introduction Improving ASP.NET Website Performance Development Tips Some more development tips Configuration Tips Some more Configurations Tips Conclusion
  3. 3. About Me Brij Bhushan Mishra Microsoft ASP.NET/IIS MVP Former CodeProject MVP Blogger/Author/Speaker @brij_bhushan
  4. 4. ASP.NET Pages Keep Page size small  Include all the referred files (CSS, JS, images)  Move CSS/Javascript to separate files  Remove HTML comments, Extra spaces  Ensure all are cached at Clients Use isPostback judicially
  5. 5. ASP.NET Pages Check your PageSource and see the __VIEWSTATE variable Minimize ViewState – Turn off if not using ASP.NET 4 : Enable ViewState at Control Level  Controls got a new property ViewStateMode  Enabled  Disabled  Inherit Demo
  6. 6. ASP.NET Pages Add Caching Wherever appropriate  Output  Fragment  Cache API Avoid using Application variable, use cache instead. Cache is robust and provides a wide list of options for intelligently managing application level data
  7. 7. Paging at Database level Most of us do paging at Application level. It could be hazardous if you have large amount of data Optimize the paging based on your requirement and data
  8. 8. Lazy Loading is not a Silver Bullet Lazyloading is good but not every time. Blindly enabling lazy loading and using it could degrade the performance. You might end up hitting database again and again that could be easily loaded in single database hit.
  9. 9. Use Ajax calls judiciously Avoid UpdatePanels Prefer ClientSide Ajax (True Ajax) Demo
  10. 10. Use SQL profiler to check the hits Run the SQL profiler when access your page. You might be unknowingly hitting database several times. It’s very common using any ORM tool like Entity Framework This is one of the main reason of slow applications
  11. 11. Use using to avoid Memory Leaks If a Type implements IDisposable then it is a right candidate to use with using statement. While leaving the using block, Dispose method will be itself called.
  12. 12. Fixed the Width and Height <img /> If you know the width and height of an image. Provide it before hand else your browser will keep guessing until it get downloaded. Page loads faster because browser assigns the required areas to image before it gets downloaded
  13. 13. Understand Loops Best loop For Next Foreach (IEnumerable) Linq loops
  14. 14. String, StringBuilder, String.join For static strings, use string. For string manipulation, StringBuilder should be used.  The StringBuilder class starts with a default initial capacity of 16  If you know the max size that will be taken care by stringbuilder, create you object like StringBuilder sb = new StringBuilder(2000); StringBuilder is not best in every case If you have already set of fixed set of string to concatenate, use string.join
  15. 15. Image Sprites Have lots of images and paying an HTTPRequest for each of them on your page? ASP.NET provides a solution that is available via Nuget Package Run the Nuget package - Install-Package AspNetSprites-WebFormsControl Demo
  16. 16. Bundling and Minification This feature is introduced in ASP.NET 4.5. This enables to bundle all the script files into single file while loading at the browser. Minification is also applied to these files so that it’s size get reduced Prior to ASP.NET 4.5, people used to write their own custom code or some third party plugins to achieve it. Demo
  17. 17. Script reference at bottom of the page Reference the scripts files at bottom of the page. Problem with scripts that It blocks parallel download
  18. 18. HTTPCompression Turn on HTTPCompression for static and dynamic content (for dynamic content, give time to decide) It reduces the size significantly of HTML content For, IIS7 and IIS 8, go to IIS Manager -> Feature View of the website . Click on Compression and enable.  Only compress which file size is larger. (more than few bytes) IIS 6 – Can be done via running some coomand, I have written a post on it. httpcompression-at-iis6/
  19. 19. Review the files that you are downloadingeach page ASP.NET project by default provides many scripts and other file with default project template. Remove them if you are not using it. Also, have another check while shipping the project
  20. 20. Remove HTTP Modules ASP.NET Page request processing Request Response HTTPModule 1 HTTPModule 2 HTTPModule 3 . . . HTTPModule n HTTP Handler
  21. 21. Remove HTTP Modules contd. There are many HTTPModules by default enabled. Remove all the modules which is not used Demo
  22. 22. Use startMode Attribute Whenever a site is updated, IIS recompiles the application at first request. It may take long on the first request. Also, most of the time, we load lot of data in cache etc at first request. This attribute is part of IIS and is available applicationHost.config at C:WindowsSystem32inetsrvconfigapplicationHost.config It is set at application pool level as <applicationPools> <add name="MyAppWorkerProcess" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" /> </applicationPools>
  23. 23. Conclusion Questions? Thank You