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.
Note
This is a draft version of the PR, which I will continue updating during development. Currently, there are several logs and benchmark traces in the code to visualize performance bottlenecks and identify areas needing optimization. These logs and traces will be removed in the final version.
Please note that the code changes in this PR are not final. These are preliminary modifications aimed at outlining the potential impact of the optimization strategies. The final PR version will include improvements for readability, efficiency, and maintainability.
Related to #43, #44
Summary
I created a basic benchmark to track key performance metrics. Here are the results:
Perfetto trace to examine the hierarchy and relative cost of each operation
blurScopeAverageMs
represents the total time spent on the entire blurring operation. Currently, this takes about 18ms per frame, which is quite expensive. Given the display's refresh rate of 90Hz on a Pixel 6 I tested on, our frame budget is around 11ms, meaning this blur process is exceeding our budget.Analysis
We have a few costly operations, including:
GraphicsLayer
and then fetching data from GPU memory to CPU, which is expensive and time-intensive.Potential Optimizations
1. Move Blurring to a Processing Queue
To prevent blocking the
onDraw
, we could offload the blurring to a processing queue that continuously updates an output state, drawing the resultant bitmap as needed.2. Output Bitmap Caching
Simple caching of the output bitmap has already shown improvements. By reusing the output bitmap instead of recreating it each time, we reduce redundant allocations. To further refine this, we’ll need to monitor the cached bitmap’s configuration and dimensions to ensure they match the input bitmap.
Benchmark Results with Caching
Initial benchmarking shows improvements with cached output bitmaps:
Additional Improvements Under Consideration
This is an ongoing PR; further updates and optimizations will be documented as development progresses. At least I'll try 😅