Skip to content

Fix initial feed load performance and relay timing#20

Merged
barrydeen merged 1 commit intomainfrom
fix/initial-feed-load-performance
Feb 20, 2026
Merged

Fix initial feed load performance and relay timing#20
barrydeen merged 1 commit intomainfrom
fix/initial-feed-load-performance

Conversation

@barrydeen
Copy link
Copy Markdown
Owner

Summary

  • Await relay connections before subscribing: subscribeFeed() was firing immediately after updateRelays(), but WebSocket connections are async — relay.send() silently drops messages when not connected. Now waits for at least 3 relays (5s timeout).
  • Reduce per-relay limit 100→25: With outbox routing to 30+ scored relays, limit=100 per relay meant thousands of events flooding in simultaneously, each triggering processRelayEvent → addEvent → StateFlow → recompose. 25 per relay is plenty for the initial screen; loadMore() handles pagination.
  • Tighten adaptive time windows: Previous windows were too aggressive for small follow counts (7 days for ≤20 follows). Now: 2d/12h/4h/1h/15m instead of 7d/48h/12h/3h/30m.
  • Fix stale relay index in reconnectAll(): Dead ephemeral relays were removed from ephemeralRelays but not relayIndex, causing sends to dead relays on subsequent lookups.
  • Fix O(n) → O(1): Replace !in ephemeralRelays.values scan with containsKey lookup.

Test plan

  • Open app fresh — feed should load quickly with ~20-30 recent notes, no jank
  • Scroll down to trigger loadMore — older notes should paginate in smoothly
  • Switch to relay feed and back to follows — should show same notes
  • Account with few follows (≤20) — should see recent posts, not week-old content
  • Account with many follows (300+) — should load fast with tight 4h window
  • Background and resume — feed should reload correctly

…windows

The initial feed was laggy because limit=100 is per-relay — with 30+
scored relays via outbox routing, thousands of events flooded in
simultaneously, each triggering recompose.

Changes:
- Await at least 3 relay connections before subscribing (prevents
  messages being silently dropped by not-yet-connected relays)
- Reduce initial feed limit from 100 to 25 per relay (loadMore handles
  pagination for older content)
- Tighten adaptiveSince windows: 7d→2d for ≤20 follows, 48h→12h for
  ≤100, 12h→4h for ≤300, 3h→1h for ≤700, 30m→15m for 700+
- Single relay feed keeps limit=50 (only one relay, no multiplication)
- Fix reconnectAll() not cleaning relayIndex for dead ephemeral relays
- Fix O(n) ephemeralRelays.values scan → O(1) containsKey lookup
@barrydeen barrydeen merged commit 75390b3 into main Feb 20, 2026
@barrydeen barrydeen deleted the fix/initial-feed-load-performance branch March 4, 2026 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant