Anton Shilov
03/04/2022, 11:29 AMonDraw
callback is considered a bad practice. In compose official docs we see creating instances of Offset, Path, etc. in DrawScope.
Is it going to be impacting draw performance the same way as in views? Or we shouldn't care about such things in compose world?Filip Wiesner
03/04/2022, 11:47 AMPath
but Offset
is inline (value) class so that shouldn't be a problemade
03/04/2022, 12:20 PMAnton Shilov
03/04/2022, 12:35 PMAlbert Chang
03/04/2022, 2:07 PMOffset
, Color
) are inline classes, which are essentially primitive types, so there isn’t any object allocations when using these classes.
Secondly, that rule was proposed in the early years of Android, when it was still using Dalvik. ART is much better in this respect, and the performance of mobile chips has also improved a lot. Generally I don’t think this should be a big problem now. You can start to think about optimization when you actually see some performance issues.Adam Powell
03/04/2022, 2:13 PMModifier.drawWithCache
is a good example of an API designed for helping you with this; you get an outer block for creating things you might reuse over time and an inner block for drawing using those same object instancesFilip Wiesner
03/04/2022, 2:21 PMwe've done this in the deeper compose internals so that in the common case, you don't have to go this far yourselfSame reasoning as with enums in the "old days" (enums being represented with Integers instead of an actual enum)
Adam Powell
03/04/2022, 2:22 PMFilip Wiesner
03/04/2022, 2:26 PMAnton Shilov
03/04/2022, 3:46 PM