Skip to content

Conversation

@ApoloApps
Copy link

@ApoloApps ApoloApps commented Nov 1, 2025

optimizing some functions SkiaBackedCanvas that were creating Paint() objects needlessly (mimicking android functions basically). There is still room for removing unnecessary allocations. See comments below

Testing

(Optional) Describe how you tested your changes (provide a snippet or/and steps)

(Optional) This should be tested by QA

Release Notes

N/A

@MatkovIvan MatkovIvan merged commit c87d3a7 into JetBrains:jb-main Nov 14, 2025
17 checks passed
@ApoloApps ApoloApps deleted the microOptimizeSkikoCanvas branch November 15, 2025 12:49
igordmn pushed a commit to JetBrains/skiko that referenced this pull request Dec 10, 2025
Added some functions to Skia canvas to be able to avoid creating
intermediate objects (SkRect, SkRRect, etc) on some hot paths.
See [this
conversation](JetBrains/compose-multiplatform-core#2543 (comment))
for the context of the PR.
This is the first step to allow for Compose Ui SkiaBackedCanvas to avoid
unnecessary intermediate allocations:
1.
https://github.com/JetBrains/compose-multiplatform-core/blob/47af63a3986292608982f421bb345eb0a2032a98/compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedCanvas.skiko.kt#L189
2.
https://github.com/JetBrains/compose-multiplatform-core/blob/47af63a3986292608982f421bb345eb0a2032a98/compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedCanvas.skiko.kt#L141
3.
https://github.com/JetBrains/compose-multiplatform-core/blob/47af63a3986292608982f421bb345eb0a2032a98/compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedCanvas.skiko.kt#L128
4.
https://github.com/JetBrains/compose-multiplatform-core/blob/47af63a3986292608982f421bb345eb0a2032a98/compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedCanvas.skiko.kt#L189
5.
https://github.com/JetBrains/compose-multiplatform-core/blob/47af63a3986292608982f421bb345eb0a2032a98/compose/ui/ui-graphics/src/skikoMain/kotlin/androidx/compose/ui/graphics/SkiaBackedCanvas.skiko.kt#L211
among others.
**Next steps**
-> open pr in Compose Ui to use these more optimized functions
-> More optimizations on the Skiko side, Matrixes is a good example, CMP
and Skiko are processing Matrixes 2 times, toSkiaMatrix, which basically
is the same as a wrapper around FloatArray and then in the toInterop
method which copies the array (unavoidable). A good optimization would
be to just pass the Compose Matrix underlying `values` property which is
a FloatArray that toInterop accepts and so a lot of intermediate objects
and transformations could be avoided altogether
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.

2 participants