Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canvas.saveLayer is relatively expensive #14

Closed
kelvinwatson opened this issue Apr 21, 2023 · 2 comments
Closed

Canvas.saveLayer is relatively expensive #14

kelvinwatson opened this issue Apr 21, 2023 · 2 comments

Comments

@kelvinwatson
Copy link

kelvinwatson commented Apr 21, 2023

Was doing some digging on canvas.withSaveLayer and noticed that its documentation says:

Performance considerations

Generally speaking, Canvas.saveLayer is relatively expensive.

There are a several different hardware architectures for GPUs (graphics processing units, the hardware that handles graphics), but most of them involve batching commands and reordering them for performance. When layers are used, they cause the rendering pipeline to have to switch render target (from one layer to another). Render target switches can flush the GPU's command buffer, which typically means that optimizations that one could get with larger batching are lost. Render target switches also generate a lot of memory churn because the GPU needs to copy out the current frame buffer contents from the part of memory that's optimized for writing, and then needs to copy it back in once the previous render target (layer) is restored.

However, the documentation doesn't offer any alternative. Is there any recommendation for replacing this call?
https://developer.android.com/topic/performance/vitals/render#rendering_performance_renderthread

@valentinilk
Copy link
Owner

That's something that is still on my todo list. In the beginning, the method's documentation didn't include the warning. When they added it, I wasn't able to find a better solution. The implementation currently relies on BlendMode, which seems to require withSaveLayer.
Open for suggestions. :)

Are you experiencing any lags, due to the shimmer libary?

@valentinilk
Copy link
Owner

Had a deeper look in the meantime. It is not possible to get rid of the withSaveLayer. As the shimmer is usually not shown for an eternity, the effect on the battery should be minimal.

@valentinilk valentinilk closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
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

No branches or pull requests

2 participants