Skip to content

⚡ Batch updates to AppWidgetManager using array of IDs#24

Open
LeanBitLab wants to merge 7 commits intomasterfrom
perf/batch-widget-updates-4669301554577800075
Open

⚡ Batch updates to AppWidgetManager using array of IDs#24
LeanBitLab wants to merge 7 commits intomasterfrom
perf/batch-widget-updates-4669301554577800075

Conversation

@LeanBitLab
Copy link
Copy Markdown
Owner

💡 What: The optimization implemented
I changed AwidgetProvider.updateAppWidget to accept an IntArray of appWidgetIds rather than a single appWidgetId: Int. I then modified onUpdate, onReceive inside AwidgetProvider and WidgetUpdateWorker.doWork() to pass the original appWidgetIds array instead of executing a for loop over them.

🎯 Why: The performance problem it solves
Previously, the method AwidgetProvider.onUpdate would loop over appWidgetIds and run everything required to build a widget (reading SharedPreferences, disk IO, weather data fetching and string manipulations) independently for each appWidgetId. Since the resulting RemoteViews layouts 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 RemoteViews precisely once per global update trigger and passing the array of IDs down to AppWidgetManager.updateAppWidget(IntArray, RemoteViews), we eliminate all duplicated IO/processing operations.

📊 Measured Improvement:
By making this change, the computational complexity of evaluating all updates on standard TICK and FULL modes scales down from $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 SharedPreferences lookup 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

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.
@google-labs-jules
Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

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.
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