From e21883d892976b1f38c352dec14ffb9d9cdf4b47 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Wed, 8 Dec 2021 10:05:36 -0600 Subject: [PATCH] Blazor performance/AOT/RR updates (#24233) --- aspnetcore/blazor/host-and-deploy/webassembly.md | 6 ++++-- aspnetcore/blazor/performance.md | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/aspnetcore/blazor/host-and-deploy/webassembly.md b/aspnetcore/blazor/host-and-deploy/webassembly.md index 7777f6de47..3bd9b03919 100644 --- a/aspnetcore/blazor/host-and-deploy/webassembly.md +++ b/aspnetcore/blazor/host-and-deploy/webassembly.md @@ -27,7 +27,7 @@ The following deployment strategies are supported: Blazor WebAssembly supports [ahead-of-time (AOT) compilation](/dotnet/standard/glossary#aot), where you can compile your .NET code directly into WebAssembly. AOT compilation results in runtime performance improvements at the expense of a larger app size. -Without enabling AOT compilation, Blazor WebAssembly apps run on the browser using a .NET Intermediate Language (IL) interpreter implemented in WebAssembly. Because the .NET code is interpreted, apps typically run slower than they would on a server-side [.NET just-in-time (JIT) runtime](/dotnet/standard/glossary#jit). AOT compilation addresses this performance issue by compiling an app's .NET code directly into WebAssembly for native WebAssembly execution by the browser. The AOT performance improvement can yield dramatic improvements for apps that execute CPU intensive tasks. The drawback to using AOT compilation is that AOT-compiled apps are generally larger than their IL-interpreted counterparts, so they usually take longer to download to the client when first requested. +Without enabling AOT compilation, Blazor WebAssembly apps run on the browser using a .NET Intermediate Language (IL) interpreter implemented in WebAssembly. Because the .NET code is interpreted, apps typically run slower than they would on a server-side [.NET just-in-time (JIT) runtime](/dotnet/standard/glossary#jit). AOT compilation addresses this performance issue by compiling an app's .NET code directly into WebAssembly for native WebAssembly execution by the browser. The AOT performance improvement can yield dramatic improvements for apps that execute CPU-intensive tasks. The drawback to using AOT compilation is that AOT-compiled apps are generally larger than their IL-interpreted counterparts, so they usually take longer to download to the client when first requested. For guidance on installing the .NET WebAssembly build tools, see . @@ -53,7 +53,9 @@ The size of an AOT-compiled Blazor WebAssembly app is generally larger than the One of the largest parts of a Blazor WebAssembly app is the WebAssembly-based .NET runtime (`dotnet.wasm`) that the browser must download when the app is first accessed by a user's browser. Relinking the .NET WebAssembly runtime trims unused runtime code and thus improves download speed. -Runtime relinking is performed automatically when you publish an app. The size reduction is particularly dramatic when disabling globalization. For more information, see . For guidance on installing the .NET WebAssembly build tools, see . +Runtime relinking requires installation of the .NET WebAssembly build tools. For more information, see . + +With the .NET WebAssembly build tools installed, runtime relinking is performed automatically when an app is published. The size reduction is particularly dramatic when disabling globalization. For more information, see . ## Customize how boot resources are loaded diff --git a/aspnetcore/blazor/performance.md b/aspnetcore/blazor/performance.md index 2918a3dbcd..c8005d19e5 100644 --- a/aspnetcore/blazor/performance.md +++ b/aspnetcore/blazor/performance.md @@ -713,8 +713,16 @@ function jsInteropCall() { } ``` +## Ahead-of-time (AOT) compilation + +[Ahead-of-time (AOT) compilation](/dotnet/standard/glossary#aot) compiles a Blazor app's .NET code directly into native WebAssembly for direct execution by the browser. AOT-compiled apps result in larger apps that take longer to download, but AOT-compiled apps usually provide better runtime performance, especially for apps that execute CPU-intensive tasks. For more information, see . + ## Minimize app download size +### Runtime relinking + +For information on how runtime relinking minimizes an app's download size, see . + ### Use `System.Text.Json` Blazor's JS interop implementation relies on , which is a high-performance JSON serialization library with low memory allocation. Using shouldn't result in additional app payload size over adding one or more alternate JSON libraries.