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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
This commit is contained in:
thepraandClaude Opus 5.5 committed 2026-10-05 23:17:48 +02:00
1 parent da98addf76
commit 2f29872745
1 file changed
+20 -2
+20 -2
View File
@@ -67,11 +67,15 @@
DotNetObjectReference<GlobePanel> reference; DotNetObjectReference<GlobePanel> reference;
PeriodicTimer statsTimer; PeriodicTimer statsTimer;
readonly CancellationTokenSource cancellation = new(); 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; GlobeStats stats;
protected override void OnInitialized() => IsLoading = false; protected override void OnInitialized() => IsLoading = false;
protected override void OnParametersSet() => postsHandedOver = true;
protected override async Task OnAfterRenderAsync(bool firstRender) protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
await base.OnAfterRenderAsync(firstRender); await base.OnAfterRenderAsync(firstRender);
@@ -86,8 +90,12 @@
statsTimer = new(TimeSpan.FromSeconds(1)); statsTimer = new(TimeSpan.FromSeconds(1));
_ = ReadStats(cancellation.Token); _ = ReadStats(cancellation.Token);
} }
if (postsHandedOver)
{
postsHandedOver = false;
await SendPosts(); await SendPosts();
} }
}
catch (JSDisconnectedException) catch (JSDisconnectedException)
{ {
} }
@@ -105,7 +113,17 @@
var located = Posts.Where(p => p.Location is not null).ToList(); var located = Posts.Where(p => p.Location is not null).ToList();
var self = InstanceService.Known(InstanceService.SelfHost); 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) if (fingerprint == sentFingerprint)
return; return;
sentFingerprint = fingerprint; sentFingerprint = fingerprint;