diff options
author | Steve Sanderson <SteveSandersonMS@users.noreply.github.com> | 2020-06-29 14:17:45 +0300 |
---|---|---|
committer | Steve Sanderson <SteveSandersonMS@users.noreply.github.com> | 2020-06-29 14:32:32 +0300 |
commit | e38097d1de5b5e2eaebf0843abef8024d8d30272 (patch) | |
tree | 127a9ea158dc3e82efe4d6e7d6ea23c39bbb9f39 /src | |
parent | 7b57f3d12f93e0152a80101147cbd91548d45af4 (diff) |
Manual approximations to the optimisations we'll addstevesa/blazor-perf-5.0-baseline-optimized
Diffstat (limited to 'src')
4 files changed, 21 insertions, 22 deletions
diff --git a/src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts b/src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts index ae1e93c6bd..6d07cce787 100644 --- a/src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts +++ b/src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts @@ -12,6 +12,11 @@ const appBinDirName = 'appBinDir'; const uint64HighOrderShift = Math.pow(2, 32); const maxSafeNumberHighPart = Math.pow(2, 21) - 1; // The high-order int32 from Number.MAX_SAFE_INTEGER +const stringCache = new Map<number, string | null>(); +export function clearMonoPlatformStringCache() { + stringCache.clear(); +} + // Memory access helpers // The implementations are exactly equivalent to what the global getValue(addr, type) function does, // except without having to parse the 'type' parameter, and with less risk of mistakes at the call site @@ -119,7 +124,13 @@ export const monoPlatform: Platform = { return unboxedValue; } - return BINDING.conv_string(fieldValue as any as System_String); + if (stringCache.has(fieldValue)) { + return stringCache.get(fieldValue)!; + } + + const result = BINDING.conv_string(fieldValue as any as System_String); + stringCache.set(fieldValue, result); + return result; }, readStructField: function readStructField<T extends Pointer>(baseAddress: Pointer, fieldOffset?: number): T { diff --git a/src/Components/Web.JS/src/Rendering/Renderer.ts b/src/Components/Web.JS/src/Rendering/Renderer.ts index 06b8ba3985..d797b59693 100644 --- a/src/Components/Web.JS/src/Rendering/Renderer.ts +++ b/src/Components/Web.JS/src/Rendering/Renderer.ts @@ -4,6 +4,7 @@ import '../Environment'; import { RenderBatch } from './RenderBatch/RenderBatch'; import { BrowserRenderer } from './BrowserRenderer'; import { toLogicalElement, LogicalElement } from './LogicalElements'; +import { clearMonoPlatformStringCache } from '../Platform/Mono/MonoPlatform'; interface BrowserRendererRegistry { [browserRendererId: number]: BrowserRenderer; @@ -32,6 +33,8 @@ export function attachRootComponentToElement(elementSelector: string, componentI } export function renderBatch(browserRendererId: number, batch: RenderBatch): void { + clearMonoPlatformStringCache(); + const browserRenderer = browserRenderers[browserRendererId]; if (!browserRenderer) { throw new Error(`There is no browser renderer with ID ${browserRendererId}.`); diff --git a/src/Components/benchmarkapps/Wasm.Performance/TestApp/Shared/FastGrid/Grid.razor b/src/Components/benchmarkapps/Wasm.Performance/TestApp/Shared/FastGrid/Grid.razor index 0806655e31..d3fcd8efae 100644 --- a/src/Components/benchmarkapps/Wasm.Performance/TestApp/Shared/FastGrid/Grid.razor +++ b/src/Components/benchmarkapps/Wasm.Performance/TestApp/Shared/FastGrid/Grid.razor @@ -3,26 +3,15 @@ <CascadingValue IsFixed="true" Value="this">@ChildContent</CascadingValue> <table @attributes="@Attributes"> - <thead> - <tr> - @foreach (var col in columns) + <thead><tr>@foreach (var col in columns) { col.RenderHeader(__builder); - } - </tr> - </thead> - <tbody> - @foreach (var item in Data) + }</tr></thead><tbody>@foreach (var item in Data) { - <tr @key="item.GetHashCode()" class="@(RowClass?.Invoke(item))"> - @foreach (var col in columns) + <tr @key="item.GetHashCode()" class="@(RowClass?.Invoke(item))">@foreach (var col in columns) { col.RenderCell(__builder, item); - } - </tr> - } - </tbody> -</table> + }</tr>}</tbody></table> @code { [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object> Attributes { get; set; } diff --git a/src/Components/benchmarkapps/Wasm.Performance/TestApp/Shared/FastGrid/GridColumn.razor b/src/Components/benchmarkapps/Wasm.Performance/TestApp/Shared/FastGrid/GridColumn.razor index aa9c6cfd5b..bc7ab58229 100644 --- a/src/Components/benchmarkapps/Wasm.Performance/TestApp/Shared/FastGrid/GridColumn.razor +++ b/src/Components/benchmarkapps/Wasm.Performance/TestApp/Shared/FastGrid/GridColumn.razor @@ -12,12 +12,8 @@ } internal void RenderHeader(RenderTreeBuilder __builder) - { - <th>@Title</th> - } + {<th>@Title</th>} internal void RenderCell(RenderTreeBuilder __builder, TRowData rowData) - { - <td>@ChildContent(rowData)</td> - } + {<td>@ChildContent(rowData)</td>} } |