Oliver
Oliver
CC#
Created by Oliver on 12/18/2024 in #help
Optimizing Large i18n Loading in Blazor
I added now to all steps a timestamp. On my macbook pro which is a fast machine it took around 4 seconds for loading and deserializing everything. I dont use any library for accessing the local storage (see below). For Deserialization i use System.Text.Json This is for loading out of local storage
public static ValueTask<string> GetFromLocalStorage(this IJSRuntime js, string key)
{
return js.InvokeAsync<string>("localStorage.getItem", key);
public static ValueTask<string> GetFromLocalStorage(this IJSRuntime js, string key)
{
return js.InvokeAsync<string>("localStorage.getItem", key);
var stopwatch = new Stopwatch();
stopwatch.Start();

Console.WriteLine($"LoadCachedLanguage Start {stopwatch.Elapsed.TotalSeconds}");
string rawCached = await js.GetFromLocalStorage("CachedLang");
Console.WriteLine($"LoadCachedLanguage End {stopwatch.Elapsed.TotalSeconds}");

if (string.IsNullOrEmpty(rawCached))
return;

Console.WriteLine($"Deserialization Start {stopwatch.Elapsed.TotalSeconds}");
var cachedLanguage = JsonSerializer
.Deserialize<Dictionary<string, LanguageEntry>>(rawCached);
Console.WriteLine($"Deserialization End {stopwatch.Elapsed.TotalSeconds}");
var stopwatch = new Stopwatch();
stopwatch.Start();

Console.WriteLine($"LoadCachedLanguage Start {stopwatch.Elapsed.TotalSeconds}");
string rawCached = await js.GetFromLocalStorage("CachedLang");
Console.WriteLine($"LoadCachedLanguage End {stopwatch.Elapsed.TotalSeconds}");

if (string.IsNullOrEmpty(rawCached))
return;

Console.WriteLine($"Deserialization Start {stopwatch.Elapsed.TotalSeconds}");
var cachedLanguage = JsonSerializer
.Deserialize<Dictionary<string, LanguageEntry>>(rawCached);
Console.WriteLine($"Deserialization End {stopwatch.Elapsed.TotalSeconds}");
That are the results: LoadCachedLanguage Start 0 LoadCachedLanguage End 2,8571 Deserialization Start 2,8576999 Deserialization End 4,2311999
14 replies
CC#
Created by Oliver on 12/18/2024 in #help
Optimizing Large i18n Loading in Blazor
I put some console logs around and its more or less the serialization and loading from localstorage. The fetching is not the problem. My guess is the translation layer between wasm and js is the problem. Thats why i asked if there is magic way of duing it.
14 replies
CC#
Created by Oliver on 12/18/2024 in #help
Optimizing Large i18n Loading in Blazor
An Api endpoint.
14 replies
CC#
Created by Oliver on 12/18/2024 in #help
Optimizing Large i18n Loading in Blazor
Do you have some experience with indexedDb? Do you now if its faster to query that instead of deserializing everything in the beginning.
14 replies
CC#
Created by Oliver on 12/18/2024 in #help
Optimizing Large i18n Loading in Blazor
This is only english 😅
14 replies