A
compiled list of possible sources of improvement are below:
General
·
Make use of a profiler to discover memory leaks and performance
problems in your application. personally I suggest dotTrace
·
Run your site in Release mode, not Debug mode, when in production,
and also during performance profiling. Release mode is much faster. Debug mode
can hide performance problems in your own code.
Caching
·
Use CompiledQuery.Compile() recursively avoiding
recompilation of your query expressions
·
Cache not-prone-to-change content using OutputCacheAttribute to save unnecessary and action executions
·
Use cookies for frequently accessed non sensitive information
·
Consider using the RouteName to organize your routes
and then use it to generate your links, and try not to use the expression tree
based ActionLink method.
·
Consider implementing a route resolution caching strategy
·
Put repetitive code inside your PartialViews, avoid render it xxxx times: if you end up
calling the same partial 300 times in the same view, probably there is
something wrong with that. Explanation And
Benchmarks
Routing
·
Use to Url.RouteUrl("User",
new { username = "joeuser" }) to specify routes. ASP.NET MVC
Perfomance by Rudi Benkovic
Security
·
Use Forms Authentication, Keep your frequently accessed sensitive
data in the authentication ticket
DAL
·
Consider second level cache for your queries and add them an scope
and a timeout i.e. NHibernate
Second Cache
Load balancing
·
Utilize reverse proxies, to spread the client load across your app
instance. (Stack Overflow uses HAProxy (MSDN).
Client side
·
Use AJAX to update components of your UI, avoid a whole page
update when possible.
·
Consider implement a pub-sub architecture -i.e. Comet- for content
delivery against reload based in timeouts.
·
Move charting and graph generation logic to the client side if
possible. Graph generation is a expensive activity. Deferring to the client
side your server from an unnecessary burden, and allows you to work with graphs
locally without make a new request (i.e. Flex charting, jqbargraph, MoreJqueryCharts).
·
Keep cookie size small, since cookies are sent to the server on every
request.
Global configuration
·
If you use Razor, add the following code in your global.asax.cs,
by default, Asp.Net MVC renders with an aspx engine and a razor engine. This
only uses the RazorViewEngine.
ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new
RazorViewEngine());
·
Add gzip (HTTP compression) and static cache (images, css, ...) in
your web.config <system.webServer>
<urlCompression doDynamicCompression="true"
doStaticCompression="true" dynamicCompressionBeforeCache="true"/>
</system.webServer>
·
Remove unused HTTP Modules
·
Flush your HTML as soon as it is generated (in your web.config)
and disable viewstate if you are not using it <pages buffer="true"
enableViewState="false">
Use Sprites : Sprites is a great thing to reduce request, you merge all your
images into a single one and use css to get to good part of the sprite,
Microsoft provides a good library to do it : Sprite and Image
Optimization Preview 4.
Cache Your server object : If you have some references lists or datas which will change
rarely, you can cache them into memory instead of querying database everytime.
Use ADO.Net instead of
Entity Freamework : EF4 or EF5 are great to
reduce developement time but it will be painfull to optimize. It's more simple
to optimize a stored procedure than Entity Framework. So you should use Store
procedure as much as possible. Dapper provides a simple way to query and map
SQL with very good performance.
Cache Page or partial page: MVC Provides some easy filter to cache page according to some
parameters, so use it.
Reduce Database calls: You can create a unique Database Request that return multiple
object, check on Dapper website.
Always have a clean
architecture: Have a clean n-tiers
architecture, even on small project. It will help you to keep your code clean
and it will be easier to optimize it if needed.
You can take a look at this
template "Neos-SDI
MVC Template" which will create for you a clean architecture with lots
of performance improvements by default (check MvcTemplate website).
No comments:
Post a Comment