⚡ Batch updates to AppWidgetManager using array of IDs#24
⚡ Batch updates to AppWidgetManager using array of IDs#24LeanBitLab wants to merge 7 commits intomasterfrom
Conversation
Updated AwidgetProvider and WidgetUpdateWorker to pass an IntArray of appWidgetIds directly to AppWidgetManager.updateAppWidget instead of looping. This prevents redundant operations (loading SharedPreferences, querying database/CPs, formatting string layouts) and IO operations per instance, dramatically reducing CPU consumption when the user adds multiple instances of the same widget to the home screen.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Updated AwidgetProvider and WidgetUpdateWorker to pass an IntArray of appWidgetIds directly to AppWidgetManager.updateAppWidget instead of looping. This prevents redundant operations (loading SharedPreferences, querying database/CPs, formatting string layouts) and IO operations per instance, dramatically reducing CPU consumption when the user adds multiple instances of the same widget to the home screen.
Updated AwidgetProvider and WidgetUpdateWorker to pass an IntArray of appWidgetIds directly to AppWidgetManager.updateAppWidget instead of looping. This prevents redundant operations (loading SharedPreferences, querying database/CPs, formatting string layouts) and IO operations per instance, dramatically reducing CPU consumption when the user adds multiple instances of the same widget to the home screen.
Updated AwidgetProvider and WidgetUpdateWorker to pass an IntArray of appWidgetIds directly to AppWidgetManager.updateAppWidget instead of looping. This prevents redundant operations (loading SharedPreferences, querying database/CPs, formatting string layouts) and IO operations per instance, dramatically reducing CPU consumption when the user adds multiple instances of the same widget to the home screen.
Updated AwidgetProvider and WidgetUpdateWorker to pass an IntArray of appWidgetIds directly to AppWidgetManager.updateAppWidget instead of looping. This prevents redundant operations (loading SharedPreferences, querying database/CPs, formatting string layouts) and IO operations per instance, dramatically reducing CPU consumption when the user adds multiple instances of the same widget to the home screen.
Updated AwidgetProvider and WidgetUpdateWorker to pass an IntArray of appWidgetIds directly to AppWidgetManager.updateAppWidget instead of looping. This prevents redundant operations (loading SharedPreferences, querying database/CPs, formatting string layouts) and IO operations per instance, dramatically reducing CPU consumption when the user adds multiple instances of the same widget to the home screen.
Updated AwidgetProvider and WidgetUpdateWorker to pass an IntArray of appWidgetIds directly to AppWidgetManager.updateAppWidget instead of looping. This prevents redundant operations (loading SharedPreferences, querying database/CPs, formatting string layouts) and IO operations per instance, dramatically reducing CPU consumption when the user adds multiple instances of the same widget to the home screen.
💡 What: The optimization implemented
I changed
AwidgetProvider.updateAppWidgetto accept anIntArrayofappWidgetIdsrather than a singleappWidgetId: Int. I then modifiedonUpdate,onReceiveinsideAwidgetProviderandWidgetUpdateWorker.doWork()to pass the originalappWidgetIdsarray instead of executing aforloop over them.🎯 Why: The performance problem it solves
Previously, the method
AwidgetProvider.onUpdatewould loop overappWidgetIdsand run everything required to build a widget (readingSharedPreferences, disk IO, weather data fetching and string manipulations) independently for eachappWidgetId. Since the resultingRemoteViewslayouts only depend on global configurations/state and are completely identical for all widgets of the same type, computing and rendering these views N times and making N IPC calls is completely redundant.By building the
RemoteViewsprecisely once per global update trigger and passing the array of IDs down toAppWidgetManager.updateAppWidget(IntArray, RemoteViews), we eliminate all duplicated IO/processing operations.📊 Measured Improvement:$O(N)$ (where N is the number of installed widgets) down to effectively $O(1)$ . Specifically, if a user has 4 widgets, the IO block runs 1 time instead of 4. Since this routine includes IPC content provider calls (for tasks and events) and
By making this change, the computational complexity of evaluating all updates on standard
TICKandFULLmodes scales down fromSharedPreferenceslookup latency, testing these constraints via benchmark explicitly is impractical, but doing IO batching mathematically guarantees less overhead and lower potential for blocking ANRs inside BroadcastReceivers.PR created automatically by Jules for task 4669301554577800075 started by @LeanBitLab