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 parameter writer dictionary lookup #24466

Closed
SteveSandersonMS opened this issue Jul 31, 2020 · 0 comments · Fixed by #24536
Closed

Blazor WebAssembly perf: Optimize parameter writer dictionary lookup #24466

SteveSandersonMS opened this issue Jul 31, 2020 · 0 comments · Fixed by #24536
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

The PlainTable/ComplexTable benchmarks show that a very large proportion of the overhead of passing each parameter is due to the time we spend doing a dictionary lookup from the parameter name to the cached parameter writer. Currently it's a case-insensitive dictionary lookup which is expensive because string hashing is expensive at scale (it has to consider every character).

We could improve this by putting a further layer of caching in front of the dictionary lookups so that, based on the object identity of the string key (not its string hash), we can immediately find out whether it's a known parameter and if so what the cached writer is. To avoid consuming too much memory in worst-case scenarios (e.g., the developer continually constructs new parameter name string instances), we would limit the cache size arbitrarily (e.g., to 50 items) after which we fall back on the slower existing code path of reading directly from the underlying string-hashing dictionary. This slower path would never be triggered in typical cases, as the string keys are compile-time interned values, and usually there are only a small number of parameter names used by a given component.

Prototype implementation is at e0a4f72. This gives nearly 10% gain for the ComplexTable benchmark.

@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
@SteveSandersonMS SteveSandersonMS linked a pull request Aug 3, 2020 that will close this issue
@mkArtakMSFT mkArtakMSFT added this to the 5.0.0-rc1 milestone Aug 3, 2020
@SteveSandersonMS SteveSandersonMS added the Done This issue has been fixed label Aug 3, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Sep 2, 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

Successfully merging a pull request may close this issue.

2 participants