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:
1 parent
da98addf76
commit
2f29872745
1 file changed
+21
-3
@@ -67,11 +67,15 @@
|
||||
DotNetObjectReference<GlobePanel> 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;
|
||||
|
||||
Reference in new issue
Block a user