ASP.NET Core 1.0: Understanding ASP.NET Core 1.0 (ASP.NET 5)
Asp.net performance
-
Upload
abhishek-sur -
Category
Technology
-
view
1.201 -
download
1
Transcript of Asp.net performance
Simple steps to improve performance of ASP.NET Application
Brij Bhushan Mishra
Agenda Introduction Improving ASP.NET Website Performance Development Tips Some more development tips Configuration Tips Some more Configurations Tips Conclusion
About Me Brij Bhushan Mishra Microsoft ASP.NET/IIS MVP Former CodeProject MVP Blogger/Author/Speaker
http://brijbhushan.net @brij_bhushan [email protected]
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
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
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
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
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.
Use Ajax calls judiciously Avoid UpdatePanels Prefer ClientSide Ajax (True Ajax)
Demo
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
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.
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
Understand Loops Best loop For Next Foreach (IEnumerable) Linq loops
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 likeStringBuilder 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
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
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
Script reference at bottom of the page Reference the scripts files at bottom of the
page. Problem with scripts that It blocks parallel
download
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. http://brijbhushan.net/2010/10/17/how-to-enable-httpcompression-at-iis6/
Review the files that you are downloading each 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
Remove HTTP Modules ASP.NET Page request processing
HTTPModule 1
HTTPModule 2
HTTPModule 3
HTTPModule n
HTTP Handler
Request Response
...
Remove HTTP Modules contd. There are many HTTPModules by default
enabled. Remove all the modules which is not used
Demo
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:\Windows\System32\inetsrv\config\applicationHost.config
It is set at application pool level as <applicationPools> <add name="MyAppWorkerProcess" managedRuntimeVersion="v4.0"
startMode="AlwaysRunning" /> </applicationPools>
Conclusion Questions?
Thank You