In draw scopes, does anyone know the cost of "cons...
# compose
a
In draw scopes, does anyone know the cost of "constructing and configuring a
androidx.compose.ui.graphics.Paint
once + using
canvas.draw*
" vs. "using the
draw*
functions and letting it figure out what cached Paint is needed, configuring it on every frame"?
r
So in the second case you want to re-use the same
Paint
across multiple draw calls?
Doing this means that the rendering pipeline must make copies of the (native) paint object for each draw call. So the first approach is better
Whether this will actually impact performance depends a lot on what you are doing and at what frequency
👍🏻 1
a
In the second case, I don't interact with any Paint objects directly. The linked compose abstraction manages it automatically, which as the code shows is reusing at most two instances of Paint and setting their properties on each draw* call
r
If it's a few draw calls, it's not a big deal
❤️ 1
If you are going to do it hundreds+ of times per frame…
a
Agreed. like particles, stars, etc.
j
It’s not clear to. Why is constructing your own Paint instance more efficient than using the
DrawScope.draw*()
functions when performing hundreds of draw operations per frame?
r
Every time you modify painting parameters (let's say the color), the rendering pipeline must make a copy of the paint since rendering doesn't happen immediately
If you draw with the same parameters every time, it won't cost anything