Skip to content

perf(federation): serve fresh remote-narrative cache without a network fetch#472

Merged
tcconnally merged 1 commit into
mainfrom
perf/federation-cache-first-467
Jun 26, 2026
Merged

perf(federation): serve fresh remote-narrative cache without a network fetch#472
tcconnally merged 1 commit into
mainfrom
perf/federation-cache-first-467

Conversation

@tcconnally

Copy link
Copy Markdown
Collaborator

Problem

_resolve_remote_narrative fetched the remote unconditionally first (_fetch_remote_narrative) and only consulted the cache when the fetch failed. So every render that includes a remote federation subscription paid a synchronous HTTP request even when a fresh cached copy existed; cache_ttl_s never prevented a round-trip, despite the docstring claiming "using cache when fresh".

Fix

Read the cache first. _read_remote_cache already returns None once an entry is past cache_ttl_s, so a non-None result is provably within TTL and is served directly with no network. A fetch happens only on a cache miss or expiry, and refreshes the cache on success. The digest/conflicts/pull fan-out is already parallelized (#457/#463), so combined with this, renders with fresh subscriptions become zero-network.

Tests

  • test_resolve_serves_fresh_cache_without_fetching: a fresh entry is served without _fetch_remote_narrative being called
  • test_resolve_fetches_when_cache_expired: an expired entry falls through to a fetch

All federation suites green locally (60 passed, 19 skipped).

Closes #467

…k fetch

_resolve_remote_narrative fetched the remote unconditionally first and only
read the cache on failure, so a render that includes remote subscriptions paid
a synchronous HTTP request every time even when a fresh cached copy existed.
cache_ttl_s was effectively dead for the hot path despite the docstring's
"using cache when fresh".

Read the cache first; _read_remote_cache already returns None once past
cache_ttl_s, so a non-None result is within TTL and is served directly. Fetch
(and refresh the cache) only on a miss or expiry. The fan-out at the digest,
conflicts, and pull call sites is already parallel (#457/#463), so combined
with this most renders become zero-network.

Tests: a fresh cache serves without calling _fetch_remote_narrative; an expired
cache falls through to a fetch.

Closes #467
@tcconnally tcconnally merged commit 466d1a6 into main Jun 26, 2026
5 checks passed
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.

perf(federation): remote narratives are always fetched before the fresh cache is checked, and fan-out is sequential

1 participant