From 2f298727459498cd232bc41a6cf00e56f3a15673 Mon Sep 17 00:00:00 2001 From: thepra Date: Mon, 5 Oct 2026 23:17:48 +0200 Subject: [PATCH] The globe looks at the feed's posts only when the feed hands them over GlobePanel built a string of every located post's place on each of its renders, the stats overlay's once a second included: with two thousand posts loaded, a hundred kilobytes of formatting every second while the page sat idle. It now looks at the posts only when the feed hands them over, and compares a hash. The feed perf test (Category=Perf) loads 2000 posts as before (49 s, against 55.6 s for 1740 in the baseline run). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw --- Components/Feed/GlobePanel.razor | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Components/Feed/GlobePanel.razor b/Components/Feed/GlobePanel.razor index 559a37a..4584a04 100644 --- a/Components/Feed/GlobePanel.razor +++ b/Components/Feed/GlobePanel.razor @@ -67,11 +67,15 @@ DotNetObjectReference reference; PeriodicTimer statsTimer; readonly CancellationTokenSource cancellation = new(); - string sentFingerprint; + int? sentFingerprint; + // the posts are looked at again only when the feed hands them over, never on the stats overlay's own renders + bool postsHandedOver = true; GlobeStats stats; protected override void OnInitialized() => IsLoading = false; + protected override void OnParametersSet() => postsHandedOver = true; + protected override async Task OnAfterRenderAsync(bool firstRender) { await base.OnAfterRenderAsync(firstRender); @@ -86,7 +90,11 @@ statsTimer = new(TimeSpan.FromSeconds(1)); _ = ReadStats(cancellation.Token); } - await SendPosts(); + if (postsHandedOver) + { + postsHandedOver = false; + await SendPosts(); + } } catch (JSDisconnectedException) { @@ -105,7 +113,17 @@ var located = Posts.Where(p => p.Location is not null).ToList(); var self = InstanceService.Known(InstanceService.SelfHost); - var fingerprint = string.Join('|', located.Select(p => $"{p.Key}:{p.Location.Latitude}:{p.Location.Longitude}:{p.Location.CdnKey}")) + $"#{self?.Geo?.Latitude}"; + // a hash, not a string of every place: a feed of thousands is looked at on every page it loads + var hash = new HashCode(); + foreach (var post in located) + { + hash.Add(post.Key); + hash.Add(post.Location.Latitude); + hash.Add(post.Location.Longitude); + hash.Add(post.Location.CdnKey); + } + hash.Add(self?.Geo?.Latitude); + var fingerprint = hash.ToHashCode(); if (fingerprint == sentFingerprint) return; sentFingerprint = fingerprint;