Skip to content

Conversation

@ApoloApps
Copy link
Contributor

Added some functions to Skia canvas to be able to avoid creating intermediate objects (SkRect, SkRRect, etc) on some hot paths.
See this conversation 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

…all (on the Ui Toolkit side e.g. Compose Ui)
@MatkovIvan MatkovIvan requested a review from igordmn December 10, 2025 11:12
@igordmn igordmn merged commit 80ceb88 into JetBrains:master Dec 10, 2025
10 of 18 checks passed
@ApoloApps
Copy link
Contributor Author

Part 2 of this PR: #1140
Compose Ui PR to change referenced functions: JetBrains/compose-multiplatform-core#2647

igordmn pushed a commit that referenced this pull request Jan 28, 2026
This is part 2 of [this
pr](#1137)

**What has changed?**
1. Added more extension functions that prevent intermediate object
allocations from a lot of the Skiko api surface
2. Migrated EnumClass.values() to entries in a lot of classes (maybe
some have been missed)

**Next**
Try (important keyword here :), cause if not wrong there are Skia and
Compose diffs on how they're treated) doing less copies of Matrix

## Release Notes
Added API that can accept primitive values instead of `Rect`, `RRect`, `Offset` to avoid additional object allocation
MatkovIvan pushed a commit to JetBrains/compose-multiplatform-core that referenced this pull request Jan 28, 2026
Changes the SkiaBackedCanvas to internally use more optimized functions
based [on this Skiko PR](JetBrains/skiko#1137)
It also includes minimal changes like:
1. [Micro optimizations for DefaultOpenContextMenu to use non
iterator-allocator
functions](577e1b1)
2. [Update Modifier.drawSelectionHandle to not use Composed
Api](1cc7182)
3. [Changed BasicContextMenu's onClose to use method
reference](b7d3bac)

## Testing
N/A

## Release Notes
N/A
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.

3 participants