Repository navigation
Save strokes off the main thread in DrawingCanvasViewModel. - #136
Merged
Merged
Conversation
copybara-service
Bot
force-pushed
the
test_1022860221
branch
from
November 24, 2026 18:19
a5db63c to
bdf631c
Compare
Every finished stroke, undo, redo, erase, and clear called `saveStrokes()` on the main thread, where `OfflineNotesRepository.updateNoteStrokes` re-serialized every stroke on the canvas (JNI encode, GZIP, and JSON) before the next frame. This made drawing slower as a note accumulated strokes. Launch saves on the injected `@ApplicationScope` (backed by `Dispatchers.Default`) instead, so serialization happens off the main thread and a save still finishes if the drawing screen closes. A `Mutex` runs saves one at a time, and a save is skipped if a newer one was requested while it waited, so rapid strokes don't queue redundant full serializations. Also remove `onCleared`'s save, which launched into the already-canceled `viewModelScope` and never ran; each edit now queues its own save on `applicationScope`. PiperOrigin-RevId: 1029163215
copybara-service
Bot
force-pushed
the
test_1022860221
branch
from
November 24, 2026 18:29
bdf631c to
ccecace
Compare
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.
Save strokes off the main thread in DrawingCanvasViewModel.
Every finished stroke, undo, redo, erase, and clear called
saveStrokes()on the main thread, whereOfflineNotesRepository.updateNoteStrokesre-serialized every stroke on the canvas (JNI encode, GZIP, and JSON) before the next frame. This made drawing slower as a note accumulated strokes.Launch saves on the injected
@ApplicationScope(backed byDispatchers.Default) instead, so serialization happens off the main thread and a save still finishes if the drawing screen closes. AMutexruns saves one at a time, and a save is skipped if a newer one was requested while it waited, so rapid strokes don't queue redundant full serializations.Also remove
onCleared's save, which launched into the already-canceledviewModelScopeand never ran; each edit now queues its own save onapplicationScope.