Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reflection and performance in web

We know Reflection is a quite expensive engine. But nevertheless ASP.NET MVC is full of it. And there is so much ways to use and implement additional reflection-based practices like ORM, different mappings between DTO-entities-view models, DI frameworks, JSON-parsing and many many others.
So I wonder do they all affect performance so much that it is strongly recommended to avoid using reflection as much as possible and find any another solutions like scaffolding etc? And what is the tool to perform server's load testing?

like image 228
Sergey Metlov Avatar asked Feb 18 '23 07:02

Sergey Metlov


1 Answers

There's nothing wrong with Reflection. Just use it wisely, a.k.a cache the results so that you don't have to perform those expensive calls over and over again. Reflection is used extensively in ASP.NET MVC. For example when the controller and action names are parsed from the route, Reflection is used to find the corresponding method to invoke. Except that once found, the result is cached so that the next time someone requests same controller and action name, the method to be invoked is fetched from the cache.

So if you are using a third party framework check the documentation/source code whether it uses reflection and whether it caches the results of those calls.

And if you have to use it in your code, same rule applies => cache it.

like image 105
Darin Dimitrov Avatar answered Feb 20 '23 20:02

Darin Dimitrov