Repository navigation
Conversation
Every write to an in-memory shared key JSON-encoded the whole value on the calling thread, and the live storage kept that encoding, which nothing ever read back: a reference loads its bytes only once, when it is created, and references stay cached per key for the life of the process. For the transcript cache (up to 16 sessions, with inline images as base64) that meant tens of MB of allocation on the main thread on every change. On phones with a tight heap the main thread then waited on GC long enough to freeze (Play ANR in Heap::WaitForGcToCompleteLocked). LiveSharedBytes now does nothing for InMemory keys. The value itself stays in SharedReference, as with iOS's in-memory keys, and the transcript cache's disk copy is still written by TranscriptCacheWriter. Verified: new LiveSharedStorageTests.anInMemoryValueIsNeverEncoded failed before the change (2 encodes) and passes after it. Full scripts/check.sh on the VM passes. The first full run hit a 50 ms timing limit in AgentFileLoadingTests (50.002 ms) on the busy VM; that test passed alone and the second full run passed. Part of #244
Leaving the app flushed a pending transcript cache write on the main thread, encoding the whole cache there, before the effect switched to IO. Both flushes now run inside the IO block, still in the same order, as iOS awaits them off the main thread. Nothing relies on the file being written before the effect's first suspension: the pause flush is the only caller and no test asserts it. Also scopes the shared-storage comments and the core parity row: live storage encodes file keys on its writer thread, AppStorage and Keychain keys on the caller, and never encodes in-memory keys; the test store still encodes every key. Verified: full scripts/check.sh on the VM passes, including :feature:drawer tests.
Tarquinen
force-pushed
the
skip-encoding-in-memory-keys
branch
from
November 21, 2026 05:16
1a92047 to
55c76e6
Compare
This branch has not been deployed
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.
The app could freeze while a session's transcript updated (Play ANR: main thread waiting on garbage collection). Every change to an in-memory shared value, such as the transcript cache, turned the whole value into JSON on the main thread and kept that copy. Nothing ever read the copy back. With up to 16 cached sessions and inline images, one change could allocate tens of MB, and phones with a small heap stalled on GC.
Now in-memory keys are never encoded. The value stays in its shared reference, as with iOS's in-memory keys. The transcript cache still saves to disk on its own background writer, and leaving the app now flushes that writer on IO too instead of encoding on the main thread.
scripts/check.shpasses.