-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blazor performance optimizations #22432
Comments
Would it be possible to create "native" WebAssembly benchmarks to test Blazor against? Just to be able to decide whether any given performance related issues are present because of WebAssembly (/JS interop DOM manipulation) or because of the Blazor runtime? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@yugabe When I have critical performance requirement and default blazor is slow I generate result html by myself dinamically, sent it to js using fast low level mono api and update dom from js. |
@Lupusa87 I understand, but I feel it to be obvious that in the long run you have to have an out-of-the-box performant framework instead of a good enough manual workaround. It kind of defeats the purpose of Blazor itself to build a whole component in HTML and send the whole diff to JavaScript (you are overwriting a whole DOM subtree without considering which elements to keep, if I understood correctly). It is a good workaround, but it won't fix Blazor WASM on mobile. Have you tried using the Now, Blazor WebAssembly performance is not quite good on mobile devices. Mostly just what you said: DOM manipulation is slow because there is no way to manipulate the DOM without using JS interop. If I know correctly, direct DOM manipulation is on the roadmap for WASM vNext. If someone is competent enough to help out the WASM guys a little, I'm sure it will be greatly appreciated to speed up the delivery of that feature. |
@yugabe I use this technique only in critical parts and when it makes sense (when whole most part of dom is changing and no sense to analize changes which makes blazor slower) and shows better performance. |
@SteveSandersonMS something like this statehaschanged(true), statehaschanged can have bool parameter with default value false and if true is provided component will re-render full dom skipping diff calculations. |
@Lupusa87 Now I understand your point. What you outlined just now could help in scenarios where a full component rerender could be preferred over diffing. This sounds a good compromise if no performance gains are available otherwise, a sort of band-aid, if you like. I feel it should be an advanced only scenario though, as the vast majority of the time you shouldn't have to worry about performance so much. Like now, when you are developing, say, an ASP.NET Core backend, you are going to have about 1% of the code being performance-critical, and 99% of the time "it just works". I feel something like this should be a baseline. Now, unfortunately, performance is sub-par, but the framework and foundation are very solid. That's why I would recommend writing test applications using different alternative frameworks (Angular, React, plain JS, plain WASM) and compare performance to Blazor to find bottlenecks and possible optimization opportunities. I think that's the same method the ASP.NET Core backend team used to compare to NodeJS (but I'm just guessing). Should the full component rerender be put into a separate issue? |
Yes it is for advanced scenario and can be used in 1% of cases but it does not reduce it's importance. |
For what Lupusa is saying, why not have a way to flag a component as render always with no diff built into the framework? Then for anything where performance is key, that attribute could be applied to force full render and replacement without doing any diffing? Or is this not really possible? |
@radderz Perhaps it would be best not to get too deep in the details of this one particular scenario here, since this issue is meant to be tracking the whole range of perf-related work. If you have a specific scenario that you want to optimize, could you please post a new separate issue rather than on this thread, giving an example of the code that you're trying to make faster, and what data you have that suggests that the problem is something specific (e.g., diffing)? Thanks very much! |
@radderz @SteveSandersonMS There is a proposal (with unclear fate...) of having ability to provide control logic when to render at builder-API-level here: #21915 (further comment: #13610 (comment)) |
Battle plan:
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.... by providing more guidance/docsCovered below... by providing performant base classes (virtualization, base grid)Covered in Virtualization support #24179Update: Results of investigation
After a very extensive investigation, here are things I think we should do to complete this for 5.0:
on
. This is ultra-trivial and gives a 2-3% gain on the PlainTable/ComplexTable benchmark. Blazor WebAssembly perf: InitializeNewAttributeFrame should use culture-insensitive ordinal string comparison #24465IsFixed
when cascading values to large numbers of receivers.@attributes
is relatively expensiveSetParameterAsync
, and how to do it efficiently.<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.
The text was updated successfully, but these errors were encountered: