Repository navigation
Description
What happened
One Home read on Android allocates several full copies of the Home response, and the Room cache write allocates more for a cache entry it then throws away. On a large Home this costs tens of megabytes per read, in a few allocations of over 10 MB each.
Measured on the JVM (a temporary harness, not committed) with a synthetic Home of 48 rows × 100 items, about 5.7 M characters of JSON:
| Step | Allocated |
|---|---|
Parse the body to a JsonObject tree |
27 MB |
Decode the tree to ResolvedSection models |
11 MB |
RoomHomeCacheRepository.cacheHomeV2 |
43 MB |
That doesn't count the body read itself. safeApiV2Call calls response.bodyAsText() (shared/src/commonMain/kotlin/org/siloserver/silo/network/apiv2/ApiV2Call.kt:37). Ktor first saves the body as one byte array, and then decodes it into one String through a StringBuilder. In TV build 1.0.0 (21) this is the frame that failed to allocate 13,186,264 bytes in silo-android#623.
cacheHomeV2 and cacheHome encode the whole Home to a String and call encodeToByteArray(). Only then do they compare the size with MAX_CACHE_BYTES (1.5 MB) and drop an oversized entry (android-shared/src/androidMain/kotlin/org/siloserver/silo/common/data/repository/RoomHomeCacheRepository.kt:67-74 and 125-136). A large Home is never cached, but every read still pays for the full encode.
Steps to reproduce
Not reproduced on a device. From source and the measurement above:
- Give a profile a Home with many 100-item rows.
- Load or refresh Home on Android.
- Every successful read runs the body read, the tree parse, the decode, and the cache encode above.
Expected behavior
- The body is decoded from a stream, not from a whole-response
String. - The cache write stops encoding once it passes
MAX_CACHE_BYTES, for example by encoding into a capped stream. It doesn't build the full JSON just to discard it.
Silo version / commit
silo-android origin/main at 33945a0.
Deployment
Any.
Clients affected
Android phone and Android TV.
Relevant logs
No logs available.
Technical notes
- The fix for silo-android#623 stops Android TV from re-reading Home while the player covers it. That fix doesn't change the cost of each read.
resolveArtworkUrlsruns on theJsonElementtree (shared/src/commonMain/kotlin/org/siloserver/silo/network/ArtworkUrls.kt:22). A streaming decode would have to resolve artwork URLs on the models instead.
AI harness
Claude Code, running in T3 Code
AI tool(s)
Claude Code
AI model(s)
claude-opus-5-5
AI involvement
AI-found from source and a JVM measurement; not reproduced on a device.
Independent or adversarial review
None beyond the silo-android#623 plan review, which read the same paths.
Confirmations
- I searched open and recently closed issues and pull requests, and this is not already reported
- I reproduced this myself on a real deployment
Source: found while fixing silo-android#623
Activity