-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
After startup our application consume significant amount of memory related to MVC routing.
It currently uses .net8.
There are 700+controllers with ~60 method per controller.
Most of controllers inherited from base generic controllers hierarchy, many controllers final type generated at runtime by closing opened generic base controller.
As result at runtime there are many controllers with same method names and parameter names.
After startup we can see next memory consumers:
There are many duplicated strings in memory (~8% of all allocated objects), where strings referenced by MVC.routing take 1st, 3d, 5th, 9th ..... places
Some examples with string referenced by routing structures directly.
Parameter name:
Value | Wasted | Count |
---|---|---|
cancellationToken | 484,5 KB | 14593 |
Value | Wasted | Count |
---|---|---|
filterId | 230,83 KB | 14774 |
viewId | 173,14 KB | 14776 |
Http verb name:
Value | Wasted | Count |
---|---|---|
POST | 120,36 KB | 15407 |
GET | 67,28 KB | 11483 |
Controller action name:
Value | Wasted | Count |
---|---|---|
GetLayoutsPanelForPropertyGridAsync | 50,11 KB | 734 |
Also sparse arrays related to MVC routing are in TOP of memory killers.
Type | Wasted | Count |
---|---|---|
System.Collections.Concurrent.ConcurrentDictionary+VolatileNode<System.Type, System.Object[]>[] | 11,83 MB | 43118 |
99.9% of theses Dictionaries contains 1 element
Type | Wasted | Count |
---|---|---|
System.Collections.Generic.Dictionary+Entry<System.String[], System.Collections.Generic.List<Microsoft.AspNetCore.Http.Endpoint>>[] | 1,55 MB | 2 |
Type | Wasted | Count |
---|---|---|
Microsoft.AspNetCore.Http.Endpoint[] | 1,11 MB | 41485 |
Most of lists contains 1 element from 4 allocated by default
Describe the solution you'd like
Some string.Intern() when assigning string in routing data structures like ParameterDescriptor.Name and so on.
Some finalizing of routing initialization where TrimExcess will be called on routing collections.
Probably some nonstandard initial capacity for some routing collections.
Additional context
No response