Reuse shared Polyline cache for focused shapes; drop decoded double-cache (#1908)#1919
Merged
Conversation
…ache (#1908) A focused trip's shape was cached twice under the same shapeId with divergent policies: TripObservationRepository's ShapeCache (Polyline, LRU 100, no TTL — GTFS shapes are immutable) and FocusedTripRepository.shapeCache (decoded List<GeoPoint>, LRU 32, with an unexplained 10-minute TTL on immutable data). ensureShape() already returns the shared, deduped Polyline (coalescing the network fetch via its own SingleFlight), so the decoded cache was a redundant second copy (~2x memory, a second eviction policy, and the stray TTL). Drop it and decode on demand from the shared Polyline cache; the Location -> GeoPoint map is cheap and runs on a focus change, not the per-frame path. The fetch concurrency throttle (shapePermits) and same-shape decode coalescing (shapeFetches) are unchanged. The cross-call shape memo now lives entirely in TripObservationRepository (covered by TripObservationRepositoryTest); reframe the FocusedTripRepository test that asserted its own memo to document the delegation. Part of #1908 (finding 8, item 2). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jul 16, 2026
bmander
added a commit
that referenced
this pull request
Jul 17, 2026
FocusedTripRepository.kt conflicted because main (#1919) dropped the local shape cache while this branch dropped the local route-stop cache — after merging, neither ExpiringLruCache instance is used (routing now flows through StopsForRouteRepository's own cache, shapes through TripObservationRepository's shared Polyline cache), so the shared cache/now/cacheSize/cacheTtl plumbing is dead and removed.
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.
Addresses item 2 of #1908 (medium-severity debt review finding 8) — the first of three separate PRs closing that issue.
Problem
A focused trip's shape was cached twice under the same
shapeId, with divergent policies:TripObservationRepository'sShapeCache—Polyline, LRU 100, no TTL (GTFS shapes are immutable; rationale documented inShapeCache.kt).FocusedTripRepository.shapeCache— decodedList<GeoPoint>, LRU 32, with an unexplained 10-minute TTL on effectively-immutable data.ensureShape()already returns the shared, dedupedPolyline(coalescing the network fetch via its ownSingleFlight), so the decoded cache was a redundant second copy: ~2× memory per focused shape, a second eviction policy, and a freshness threshold that contradicts the immutability rationale one layer down.Change
FocusedTripRepository.shapeCache;fetchShapedecodes on demand from the sharedPolylinecache. TheLocation → GeoPointmap is cheap and runs on a focus change, not the per-frame render path.shapePermits) and same-shape decode coalescing (shapeFetches) — those are concurrency controls, not caching, so behavior beyond the removed cache is unchanged.routeStopCacheand itsExpiringLruCache/TTL are untouched here (the stops-for-route cache is item 1 of Focused-trip data layer: stops-for-route fetched via two paths, shapes double-cached, focusedTrips in three copies #1908, a separate PR).Tests
The cross-call shape memo now lives entirely in
TripObservationRepository(already covered byTripObservationRepositoryTest). TheFocusedTripRepositoryTestcase that assertedFocusedTripRepository's own memo is reframed to document the delegation. The within-getGeometryshared-shape dedup test is unchanged and still passes../gradlew :onebusaway-android:compileObaGoogleDebugKotlin -PwarningsAsErrors=true— clean./gradlew :onebusaway-android:testObaGoogleDebugUnitTest --tests '*FocusedTripRepositoryTest' --tests '*TripObservationRepositoryTest' --tests '*ShapeCacheTest'— greenFollow-ups (same issue, separate PRs)
🤖 Generated with Claude Code