Debug Slow Razor View

I have an ASP MVC 4 web application. One of the actions returns very slowly. I use MiniProfiler to profile the application.

We process the duration of the action itself, which is 14 ms, the problem is that at the step of the request itself it is still about 1.5 s, without the action time on the controller (see the attached image).

MiniProfiler screen shoot

As you can see, the first line length (1262.3) is the duration without children. As far as I understand, this is the time of the razor engine rupture. It is important to note that slowness persists, this is not just the first request. It never goes below 800 ms and once up to 2 seconds.

How can I profile the rendering itself? Representation is rather complicated with several partial representations in it.

+4
source share
3 answers

See if Glimpse provides a deeper understanding

http://getglimpse.com/

Rendering a view can take a very long time if routes are calculated. Check how long the rendering takes if you remove all ActionLinks and similar html helpers.

+1
source

It looks like the SQL query is executing in your view. This can happen if you use some kind of ORM structure, such as EntityFramework, which lazily loads objects and they are readily extracted from the database when you touch their properties (which happens in your view). I would recommend that you use view models and look forward to loading everything into a controller action, rather than waiting for it to happen in your view.

+3
source

I create a small class that inherits RazorViewEngine and adds profiling using MiniProfiler .

This will help me see which view or partial view takes the longest. He does not explain why, for example, due to the use of ActionLink or lengthy computation.

0
source

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


All Articles