Skip to content

Unexpected (?) memory behaviour when using multiple route attributes with route parameters #23850

@siimv

Description

@siimv

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

Repro: https://github.com/siimv/AttributeRouteMemoryUsage

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

Metadata

Metadata

Assignees

Labels

area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-routing

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions