Skip to content
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 WebAssembly perf: Optimize multiple-attributes overwrite detection #24467

Closed
SteveSandersonMS opened this issue Jul 31, 2020 · 0 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components Done This issue has been fixed feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Milestone

Comments

@SteveSandersonMS
Copy link
Member

This is part of #22432

Currently, catch-all parameters (a.k.a. additional attributes) are disproportionately expensive because of the extra time we spend normalizing the list of parameters each time we pass them to child components. We walk through the set of unmatched attributes and build a dictionary so we can detect which ones were overwritten by others. This is particularly expensive because of the cost of hashing each of the attribute name strings.

As a faster alternative, we can use a different data structure (other than Dictionary<string, int>) that is more optimized for the case where most lookups will not be a match (i.e., most parameters aren't overwritten by others). In the prototype below, SimpleStringIntDict has an API like Dictionary<string, int>, but works without having to call key.GetHashCode(). Instead it provides its own extremely basic and fast hash function that doesn't consider all the characters in the string. Since in most cases each lookup results in "no match", there's no drawback (in those cases) in having such a simplistic hash. This would only perform worse than Dictionary<string, int> in extraordinary cases, e.g., there are a large number of different parameters that all clash on this simplistic hash, and they all get overwritten many times within the same invocation. I don't expect there to be any reasonable use case like that.

Prototype implementation is at 0c09859. The default ComplexTable benchmark unfortunately doesn't make heavy use of additional attributes, but if it's changed to pass three additional attributes per <Cell>, this optimization improves its timings by 17%. So I regard this optimization as very valuable for cases where people do use additional attributes heavily.

@SteveSandersonMS SteveSandersonMS added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels Jul 31, 2020
@SteveSandersonMS SteveSandersonMS self-assigned this Jul 31, 2020
@mkArtakMSFT mkArtakMSFT added this to the 5.0.0-rc1 milestone Aug 3, 2020
@ghost ghost added Done This issue has been fixed and removed Working labels Aug 5, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Sep 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components Done This issue has been fixed feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly
Projects
None yet
Development

No branches or pull requests

2 participants