perf(federation): serve fresh remote-narrative cache without a network fetch#472
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
_resolve_remote_narrativefetched 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_snever prevented a round-trip, despite the docstring claiming "using cache when fresh".Fix
Read the cache first.
_read_remote_cachealready returnsNoneonce an entry is pastcache_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_narrativebeing calledtest_resolve_fetches_when_cache_expired: an expired entry falls through to a fetchAll federation suites green locally (60 passed, 19 skipped).
Closes #467