question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AspNet Core 3.1 Razor compilation extremely slow (dozen of minutes) for a view with big static html table

See original GitHub issue

I’ve updated an asp.net core 2.2 mvc website to core 3.1 and found razor compilation extremely slow. I’m talking dozen of minutes! After a couple of hours I’ve found the problem: I had a 5Mb razor view with a big static html table containing 9300 rows. I know this may not be a common scenario but the performance degradation - comparing to netcore 2.2 - is not acceptable and certainly deserves improvement.

I was able to reproduce just creating a new asp.net core 3.1 mvc project and adding the html table to the Home/Index.cshtml

  • ASP.NET Core version: 3.1
  • Visual Studio 2019 version 16.4.1

dotnet --info output:

.NET Core SDK (reflecting any global.json): Version: 3.1.100 Commit: cd82f021f4

Runtime Environment: OS Name: Windows OS Version: 10.0.18363 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.100\

Host (useful for support): Version: 3.1.0 Commit: 65f04fb6db

.NET Core SDKs installed: 2.2.402 [C:\Program Files\dotnet\sdk] 3.1.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
moxplodcommented, Feb 20, 2020

Hi @mkArtakMSFT here is a page load time - 18ms when razor is compiled. And I add single whitespace in the razor page and refresh, it takes around 10s in most cases. Some cases I have seen much higher. Trying to figure out how to send you a repro project.

image

In 2.2 it was definitely not noticeable like this, but do not have the time taken there recorded.

1reaction
ajaybhargavbcommented, Dec 16, 2019

@agrinei, thanks for the report. You can unblock yourself in the mean time by doing one of the following,

Option 1

Move the large static table to a separate .html file and then do,

@Html.Raw(System.IO.File.ReadAllText("Path/to/table.html"))

Option 2

Move the contents inside a script tag and embed it as a string,

<div id="mytable"></div>
<script>
    var tabledata = `
<table>
  <tr>...</tr>
  <tr>... </tr>
  ...
</table>
`;

    document.getElementById('mytable').innerHTML = tabledata;
</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

First request slow when importing Razor views from class ...
So I have an ASP.NET Core 2.1 MVC app that includes those libraries and embeds partial views. While this works, I noticed a...
Read more >
Extremely slow build for asp.net core 3.1 apps #23435
I use asp.net core 3.1.9 mvc and i'm working on a medium sized project with about 800 CS files and 400 razor views...
Read more >
Razor file compilation in ASP.NET Core
Learn how compilation of Razor files occurs in an ASP. ... Updating Razor views and Razor Pages during development while the app is...
Read more >
Call JavaScript functions from .NET methods in ASP. ...
The JS function accepts a byte array from a C# method, decodes the array, and returns the text to the component for display....
Read more >
Populate Dropdown Lists in ASP.NET MVC Razor Views
This guide presents a couple of common ways to populate dropdown lists in ASP.NET MVC Razor views, with an emphasis on producing functional ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found