Skip to content

Comments

Avoid extra text layout when null and default non-null values are mixed between calls#2634

Merged
MatkovIvan merged 1 commit intojb-mainfrom
ivan.matkov/reduce-text-style-invalidations
Dec 9, 2025
Merged

Avoid extra text layout when null and default non-null values are mixed between calls#2634
MatkovIvan merged 1 commit intojb-mainfrom
ivan.matkov/reduce-text-style-invalidations

Conversation

@MatkovIvan
Copy link
Member

@MatkovIvan MatkovIvan commented Dec 9, 2025

Follow up after debugging #2629/CMP-8028
This fix reduces the number of skia paragraph layout calls from 3 to 2 for each label in the next example:

val textMeasurer = rememberTextMeasurer(cacheSize = 100)
Canvas(Modifier.fillMaxSize().background(Color.DarkGray)) {
    for (i in 0 until 100) {
        drawText(
            textMeasurer = textMeasurer,
            text = "$i",
            topLeft = Offset(x = i % 10 * 50f, y = i / 10 * 50f),
            style = TextStyle.Default.copy(color = Color.White)
        )
    }
}

Unfortunately, a unit test for this behavior is not trivial because we don't have infra to mock final classes even on JVM now

Release Notes

N/A

@@ -160,7 +160,7 @@ private sealed interface ComputedStyle {
fontStyle?.let {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add Fixes "CMP-8028 Text color is sometimes randomly black on iOS when using Compose Multiplatform (BasicText)" in the description to update the issue

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not directly related to that, but ok

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is to notify QA to test this (or be aware) by changing "Fix version". This is only possible if it is written in "Fix..." format.

If it isn't right to mention existing issue, let's create a new one.

@MatkovIvan MatkovIvan merged commit 47af63a into jb-main Dec 9, 2025
17 checks passed
@MatkovIvan MatkovIvan deleted the ivan.matkov/reduce-text-style-invalidations branch December 9, 2025 16:11
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.

4 participants