{"id":402804,"date":"2023-11-14T15:09:48","date_gmt":"2023-11-14T14:09:48","guid":{"rendered":"https:\/\/blog.jetbrains.com\/?post_type=dotnet&#038;p=402804"},"modified":"2024-01-26T13:04:19","modified_gmt":"2024-01-26T12:04:19","slug":"automatically-analyze-asp-net-core-performance-with-dynamic-program-analysis","status":"publish","type":"dotnet","link":"https:\/\/blog.jetbrains.com\/en\/dotnet\/2023\/11\/14\/automatically-analyze-asp-net-core-performance-with-dynamic-program-analysis","title":{"rendered":"Automatically Analyze ASP.NET Core Performance With Dynamic Program Analysis"},"content":{"rendered":"\n<p>Slow web pages <a href=\"https:\/\/google.com\/search?q=page+load+time+lose+customers\" target=\"_blank\" rel=\"noopener\">may make your users or customers abandon your web application<\/a>, even before they\u2019ve had a proper look at it. You\u2019ve likely also been frustrated working with a web application that is slow to load.<\/p>\n\n\n\n<p>The good news is that the latest versions of<a href=\"https:\/\/jetbrains.com\/resharper\/nextversion\" target=\"_blank\" rel=\"noopener\"> ReSharper<\/a> and<a href=\"https:\/\/jetbrains.com\/rider\/nextversion\" target=\"_blank\" rel=\"noopener\"> JetBrains Rider<\/a>\u2019s<a href=\"https:\/\/jetbrains.com\/help\/resharper\/Dynamic_Program_Analysis.html\" target=\"_blank\" rel=\"noopener\"> Dynamic Program Analysis<\/a> come with new inspections to help you find performance issues with your ASP.NET Core MVC, Razor Pages, and Razor ViewComponents \u2013 all without having to dive into a full-blown profiler!<\/p>\n\n\n\n<p>Let\u2019s take a look at those new performance inspections for applications targeting the ASP.NET Core framework.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Dynamic Program Analysis (DPA)?<\/h2>\n\n\n\n<p>Before we dive into what\u2019s new, let\u2019s quickly recap what Dynamic Program Analysis (or DPA) is all about. DPA is a process that runs in the background of ReSharper and JetBrains Rider, and checks your application for various issues whenever you run it on your machine.<\/p>\n\n\n\n<p>DPA will check for<a href=\"https:\/\/blog.jetbrains.com\/en\/dotnet\/2020\/03\/31\/auto-detect-memory-issues-app-dynamic-program-analysis-rider-2020-1\"> issues with memory allocation<\/a> and database usage. It provides hints about allocations to large and small object heaps, but also informs you when a database query returns more rows than you expected,<a href=\"https:\/\/blog.jetbrains.com\/en\/dotnet\/2023\/03\/02\/optimizing-entity-framework-core-database-queries-with-dynamic-program-analysis\"> helping you trap N+1 queries and Cartesian explosions,<\/a> among other potential performance issues.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">DPA for ASP.NET Core applications<\/h2>\n\n\n\n<p>The ReSharper 2023.3 and JetBrains Rider 2023.3 releases now come with new inspections to make you aware of potential issues in your ASP.NET Core applications.<\/p>\n\n\n\n<p>When you see a red icon in your status bar, DPA has found a potential performance issue. Alternatively, you will see a warning in the editor gutter and highlighting in your code:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1600\" height=\"370\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2023\/11\/image-7.png\" alt=\"\" class=\"wp-image-402839\"\/><\/figure>\n\n\n\n<p>You can double-click the icon in the status bar (or press <kbd>Alt+Enter<\/kbd> and then <strong>View ASP issues<\/strong>) to open a new tool window and see the inspections that were triggered. The different tabs will show potential issues with Memory Allocation, Database, or in this case, ASP.NET.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1600\" height=\"437\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2023\/11\/image-6.png\" alt=\"\" class=\"wp-image-402828\"\/><\/figure>\n\n\n\n<p>For the <code>IndexModel.OnGet()<\/code> Razor Page in the above application, DPA detected that the average execution time is over 7 seconds. Yikes!<\/p>\n\n\n\n<p>Much like the other inspections available in DPA, the inspections for ASP.NET Core applications will require you to look more closely at your source code (or use a full-scale profiler such as<a href=\"https:\/\/jetbrains.com\/dottrace\" target=\"_blank\" rel=\"noopener\"> dotTrace<\/a> or<a href=\"https:\/\/jetbrains.com\/dotmemory\" target=\"_blank\" rel=\"noopener\"> dotMemory<\/a>). However, without having to do anything specific, DPA does make you aware of potential performance issues before your application goes to production.<\/p>\n\n\n\n<p>The new inspections in Dynamic Program Analysis that target ASP.NET Core frameworks are available in the Early Access Program for<a href=\"https:\/\/jetbrains.com\/resharper\/nextversion\" target=\"_blank\" rel=\"noopener\"> ReSharper<\/a> and<a href=\"https:\/\/jetbrains.com\/rider\/nextversion\" target=\"_blank\" rel=\"noopener\"> JetBrains Rider<\/a>. Give them a try, and see if you can find any issues in your MVC actions, Razor Pages, or ViewComponents. As always, we welcome your feedback in the comments.<\/p>\n\n\n\n<p><em>Photo by <a href=\"https:\/\/unsplash.com\/@saffu?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash\" target=\"_blank\" rel=\"noopener\">Saffu<\/a> on <a href=\"https:\/\/unsplash.com\/photos\/round-silver-colored-smartwatch-bokeh-photography-E4kKGI4oGaU?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash\" target=\"_blank\" rel=\"noopener\">Unsplash<\/a><\/em><\/p>\n","protected":false},"author":118,"featured_media":402850,"comment_status":"closed","ping_status":"closed","template":"","categories":[4992,1401],"tags":[8062,489,46,1978],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/dotnet\/402804"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/dotnet"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/types\/dotnet"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/users\/118"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/comments?post=402804"}],"version-history":[{"count":9,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/dotnet\/402804\/revisions"}],"predecessor-version":[{"id":402880,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/dotnet\/402804\/revisions\/402880"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/media\/402850"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/media?parent=402804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/categories?post=402804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/tags?post=402804"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/cross-post-tag?post=402804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}