dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.21k stars 9.95k forks source link

Consider using UTF8 literals for string literals generated from .razor and .cshtml #50788

Open tmat opened 1 year ago

tmat commented 1 year ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

The source generator currently uses regular string literals for HTML content.

For example,

__builder.AddMarkupContent(4, "<h1>Hello, world!</h1>\n\nWelcome to your new app!\n\n");

String literals are stored in the assembly in #US metadata heap using UTF16 encoding. The heap size is limited and larger apps run out of the space. See https://github.com/dotnet/aspnetcore/issues/20224.

Describe the solution you'd like

Using UTF8 literals would address this issue. UTF8 literals are stored directly in the PE image at specified RVA. The metadata heap size limitations thus do not apply.

Besides, it would likely be faster and more memory efficient to render the pages since UTF16 to UTF8 encoding might be avoided.

Additional context

No response

ghost commented 11 months ago

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

justindbaur commented 10 months ago

Would a community contribution of this be accepted?

MichalStrehovsky commented 6 months ago

Noticed this too - in the dotnet new webapiaot template app, there's 40+ kB of string literals related to the error page. This affects both startup time and use of private bytes (the literals need to be allocated somewhere and they get never freed). This would be a 20+ kB saving just for the error page.

DamianEdwards commented 4 days ago

Note I started investigating a fix to support this a while back in https://github.com/dotnet/razor/tree/damianedwards/Utf8HtmlLiterals Can't quite remember where I got to, but I think it involved a new directive to enable changing the format the HTML literals are encoded in and plumbing that all the way through to the compiler.