Should I use a static cached ResourceManager or a new instance for each web request? Does it matter?

What, if any, are the performance consequences (or others) of creating a new .NET ResourceManager for each request using new ResourceManger(myResourceType.FullName, myResourceType.Assembly) vs using the "cached instance of ResourceManager" in the generated class .Designer.cs ( MyResourceType.ResourceManager )?

I work in the context of an ASP.NET MVC 3 application using .resx files.

Edit: I'm interested in consequences that go beyond allocating resources for a new facility.

Edit: By reviewing the MSDN documentation for ResourceManager.ReleaseAllResources , it states that:

This method will shrink the working set in a running application. Any future resource lookups on this ResourceManager will be as extensive as the first lookup, since it will need to search and load resources again.

This, apparently, means that the initial discovery of a set of resources is expensive, which suggests that creating a new manager for each request can be expensive. However, the documents do not offer best practices regarding the lifetime / volume of resource managers.

+6
source share
2 answers

I made some primitive profiling (using MiniProfiler) the difference between using a cached manager (I used reflection to find a static cached manager for each type of resource) and using a new manager for every key access. The results showed that the new manager took about 45 times, which tells me that there is real performance for using the cached manager approach. However, both approaches were so quick that the difference is probably of little practical importance.

+4
source

You will have the selection of the object when it is created.

this means that you will have performance and memory implications for creating an object over and over again.

you can try and check how many garbage collection cycles you have (using performance counters) and the number of instances of the "cached" resource manager resource that is created once (per process), and therefore there are no unnecessary allocations

0
source

Source: https://habr.com/ru/post/918775/


All Articles