Internet reflection and performance

We know that Reflection is a fairly expensive engine. Nevertheless, ASP.NET MVC is full of it. And there are so many ways to use and implement additional reflection-based methods, such as ORMs, different mappings between DTO representation models, DI structures, JSON processing, and many others. Therefore, I think that they all affect productivity so much that it is strongly recommended to avoid using reflection as much as possible and find any other solutions, such as scaffolding, etc.? And what is the tool for testing server load?

+4
source share
2 answers

For stress testing, this SO post provides quite a few features: Stress testing an ASP.Net application .


I myself thought about this issue and come to the following conclusions:

  • Most people don't spend their days re-posting pages over and over again. The time it takes a user to read and consume pages that, in the worst case, contain multiple Ajax calls is minimal when you consider the time taken to visit the actual website. Even if you have a million willing users of your application, you usually wonโ€™t have to deal with millions of requests at any given time.

  • The web interface, of course, is based on string comparisons ... there are no types in the HTTP response, so any web application has to deal with tasks such as the fact of everyday life. The fewer string comparisons and dynamic objects, the better, but they are inalienable from them, inevitable.

  • Although things like matching by comparing strings or a dynamic type are slow, a site built with an uncompiled, weakly typed language like PHP will contain much more of these actions. Despite the number of possible performance gains in MVC compared to the C # console application, it is still an excellent solution for many others in the web domain.

  • Using any structure will be related to performance. An application built in C # with the .NET platform will not be intended for all purposes and tasks, as well as an application written in C ++. However, the benefits are better reliability, faster coding time and easier testing among others. Considering how the speed of computers exploded over the last ten or two years, we came to take a few extra milliseconds here and there in exchange for these advantages (which are huge).

Given these points, when developing ASP.NET MVC applications, I donโ€™t avoid things like reflection like the plague, because it is clear that they can have a very positive effect on how your application works. They are tools and, when used properly, have great advantages for many applications.

In terms of performance, I like to create the best solution I can, and then go back and run stress tests on it. Maybe the reflection that I implemented in class X is, after all, not a performance issue? In short, my first task is to build a great architecture, and the second is to optimize it to squeeze every last performance out of it.

+2
source

There is nothing wrong with Reflection. Just use it wisely, aka cache the results so you don't have to repeat these expensive calls over and over. Reflection is widely used in ASP.NET MVC. For example, when the controller and action names are parsed from a route, Reflection is used to find the appropriate method to invoke. Except that it was once found, the result is cached, so the next time someone asks for the same controller and action name, the method that is called is retrieved from the cache.

So, if you use a third-party infrastructure, check the documentation / source code to see if it uses reflection and whether it caches the results of these calls.

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

+6
source

All Articles