-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Describe the bug
I use attribute routing and I have quite many controllers. Each controller has multiple routes that it should match, for example:
[Route("test")]
[Route("{language:length(2)}/test")]
[Route("{version:int}/{language:length(2)}/test")]
In my case, this results about 2.8GB memory usage after first request (which is also slow, next requests respond fast). From the memory profiler I see a lot of objects related to DfaNode and Endpoint (also many related collections).
It doesn't seem to matter which type of constraints I use (built-in or custom) and removing the constraints (leaving just {language} doesn't affect much. It also doesn't matter if I add routes through Route attributes or use some conventions to do that.
If I use any single one (or any two) of the those routes, then memory consumption is acceptable. Adding one more route increases memory consumption even more.
Now, I understand that having a lot of routes (even more, having multiple "parallel routes") increases memory usage due to route parsing and matching, but so high usage seems a little bit odd.
To Reproduce
It contains controller files (each has 63 controllers having 3 methods each):
- TestControllersWithSimpleRoute, memory ~30mb
Using routes[Route("test1")] - TestControllersWithSimpleAndSingleConstrainedRoute, memory ~80mb
Using routes[Route("test1")] [Route("{language:length(2)}/test1")] - TestControllersWithMultipleConstrainedRoute, memory ~139mb
Using routes[Route("{language:length(2)}/test1")] [Route("{version:int}/{language:length(2)}/test1")] - TestControllersWithSimpleAndMultipleConstrainedRoutes, memory ~2.5gb
Using routes[Route("test1")] [Route("{language:length(2)}/test1")] [Route("{version:int}/{language:length(2)}/test1")]
Further technical details
- ASP.NET Core version 3.1