This question on stack overflow asks about URL generation performance. http://stackoverflow.com/questions/212201
I've forgotten about this for a while, but this was affecting the performance of our site considerably too. A colleague of mine had to deal with this, and he solved by going back to string concats/formats (*cringe*) and adding page level caching.
That was with Preview 2, but now the beta is out, we'll try again with action caching.
Has anyone else encountered this?
Is there a way to improve the performance of URL generation using the lambda method?
BTW, the lambda methods are awesome, cos the compiler quickly tells me if I've made a mistake. I love it, and would love to stick with it.
From MVC Preview 2 to the recently released MVC Beta from yesterday there have been a lot of changes to Routing. Some of those changes include performance improvements. Here are some tricks to make URL generation more performant in your application:
1. Use named routes. Named routes are an optional feature of routing. The names only apply to URL generation - they are never used for matching incoming URLs. When you specify a name when generating a URL we will only try to match that one route. This means
that even if the named route you specified is the 100th route in the route table we'll jump straight to it and try to match.
2. Put your most common routes at the beginning of the route table. This will improve performance of both URL generation as well as processing incoming URLs. Routing works based on the rule that the first match wins. If the first match is the 100th route
in your route table, then that means it had to try 99 other routes and none of them matched.
3. Don't use URL generation. Some people like it, some people don't. It's a bit tricky to master. It's nice to use if your URLs are very dynamic but it can be a bit of a hassle when you have very few URLs to begin with and perhaps you don't care about exactly
what they look like.
My favorite option is #1 since it's super easy to use and it also makes URL generation more deterministic from the app developer's perspective (that's
you!).
Thanks,
Eilon
Blog: http://weblogs.asp.net/LeftSlipper/
Marked as answer by Eilon on Oct 17, 2008 04:59 PM
CVertex
Member
147 Points
128 Posts
ASP.NET MVC URL generation performance
Oct 17, 2008 02:38 PM|LINK
This question on stack overflow asks about URL generation performance. http://stackoverflow.com/questions/212201
I've forgotten about this for a while, but this was affecting the performance of our site considerably too. A colleague of mine had to deal with this, and he solved by going back to string concats/formats (*cringe*) and adding page level caching.
That was with Preview 2, but now the beta is out, we'll try again with action caching.
Has anyone else encountered this?
Is there a way to improve the performance of URL generation using the lambda method?
BTW, the lambda methods are awesome, cos the compiler quickly tells me if I've made a mistake. I love it, and would love to stick with it.
Eilon
Contributor
5753 Points
976 Posts
Microsoft
Re: ASP.NET MVC URL generation performance
Oct 17, 2008 04:49 PM|LINK
Hi there,
From MVC Preview 2 to the recently released MVC Beta from yesterday there have been a lot of changes to Routing. Some of those changes include performance improvements. Here are some tricks to make URL generation more performant in your application:
1. Use named routes. Named routes are an optional feature of routing. The names only apply to URL generation - they are never used for matching incoming URLs. When you specify a name when generating a URL we will only try to match that one route. This means that even if the named route you specified is the 100th route in the route table we'll jump straight to it and try to match.
2. Put your most common routes at the beginning of the route table. This will improve performance of both URL generation as well as processing incoming URLs. Routing works based on the rule that the first match wins. If the first match is the 100th route in your route table, then that means it had to try 99 other routes and none of them matched.
3. Don't use URL generation. Some people like it, some people don't. It's a bit tricky to master. It's nice to use if your URLs are very dynamic but it can be a bit of a hassle when you have very few URLs to begin with and perhaps you don't care about exactly what they look like.
My favorite option is #1 since it's super easy to use and it also makes URL generation more deterministic from the app developer's perspective (that's you!).
Thanks,
Eilon