Skip to content

Move cache clearing off the main thread#477

Open
ElCruncharino wants to merge 1 commit into
LivingWithHippos:masterfrom
ElCruncharino:fix/main-thread-cache-clear
Open

Move cache clearing off the main thread#477
ElCruncharino wants to merge 1 commit into
LivingWithHippos:masterfrom
ElCruncharino:fix/main-thread-cache-clear

Conversation

@ElCruncharino

Copy link
Copy Markdown
Contributor

MainActivityViewModel.clearCache does a recursive delete over the cache directory, and it was running synchronously on whatever thread called it, which in this case is the main thread on every app start. Wrapped it in viewModelScope.launch(Dispatchers.IO) so the disk work happens off the main thread. As the cache grows this was a real path to startup jank.

clearCache did a recursive file delete synchronously in MainActivityViewModel, and MainActivity called it directly in onCreate. That blocked the UI thread with disk I/O on every cold start. The cleanup now runs inside viewModelScope.launch(Dispatchers.IO), keeping clearCache non-suspend so the call site in MainActivity does not need any changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant