Skip to content

Blazor performance optimizations #22432

Closed
@mkArtakMSFT

Description

@mkArtakMSFT

Battle plan:

  • Quantify 3.2.0 perf
    • ... for selected scenarios:
      • 3rd-party unoptimized code (ComplexTable)
      • 3rd-party optimized code (PlainTable)
      • 1st-party optimized code (FastGrid)
    • ... providing useful breakdowns of:
      • ... time in .NET rendering logic (BuildRenderTree calls, diffing, etc.)
      • ... time in the JS DOM-updating logic
  • Identify and implement optimizations, in each case quantifying the change:
    • Inside Blazor code
      • ... inside the Razor compiler, to reduce the amount of stuff we render at runtime
      • ... inside the .NET rendering logic
      • ... inside the JS DOM-updating logic
    • Inside Mono interpreter (have provided scenarios to Vlad for this effort)
    • In browser's WASM engine (this is something Vlad/Zoltan are leading and might not complete before 5.0 ships) Out of scope for this issue.
    • In 3rd-party code
      • ... by providing more guidance/docs Covered below
      • ... by providing performant base classes (virtualization, base grid) Covered in Virtualization support #24179
    • As a result of switching to CoreFX for 5.0
  • Consider backporting optimizations to 3.2.x if they yield big benefits without involving changes to user code

Update: Results of investigation

After a very extensive investigation, here are things I think we should do to complete this for 5.0:

  • Write up the main findings from the investigation
    • Exactly how perf differs between 3.2.0 and 5.0 Preview 8
    • Why the perf numbers for FastGrid/PlainTable/ComplexTable are what they are. That is, provide breakdowns showing how use of each feature adds to the totals, explaining the differences in perf in ways that justify the perf advice we will give.
  • Ensure we can keep collecting useful profiling data in the future (not just on my machine)
    • Add the ConsoleRunner project to the repo so we can easily run Blazor scenarios on the desktop interpreter
    • Begin a discussion with @BrzVlad and others responsible for the .NET interpreter about how we could merge in something like the trace collection logic so others can get profiling data in the future without needing a custom build of the runtime. Filed Consider adding profile trace export to Mono interpreter runtime#40617
  • Implement optimizations inside Blazor
  • Write up docs on how to write better-performing Blazor WebAssembly apps. For example:
    • How much overhead you should expect from each extra layer of components you add, and each extra parameter you pass. Hence you should consider inlining child components if you're rendering a large number of them.
    • Why it's so important to use IsFixed when cascading values to large numbers of receivers.
    • That @attributes is relatively expensive
    • Why, for perf-criticial components, you should consider implementing your own manual parameter assignment logic on SetParameterAsync, and how to do it efficiently.
    • How and why to use <Virtualize>

The specific optimizations I've listed above aren't the only ones I'm aware of. I've tried many things based on the profiling data. These optimizations are the ones that have the biggest impact for the least cost.

Metadata

Metadata

Labels

DoneThis issue has been fixedarea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssembly

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions