https://kotlinlang.org logo
Title
d

David W

01/12/2022, 2:18 AM
Is this normal for CfD apps? The drop is when I quit the app.
👀 1
I ran visualvm on it and it's very possible I'm not interpreting the results right, but it seems like it's just CfD doing non-stop rendering?
This is with the app just sitting, doing nothing.
k

Kirill Grouchnikov

01/12/2022, 2:31 AM
Depends on how you set up your data flow. It might look like it's doing nothing, while in fact it's recomposing the entire UI on every frame.
d

David W

01/12/2022, 2:33 AM
I'll try sprinkling breakpoints around and seeing if they're hit...
haven't had any success getting useful information from VisualVM or Mission Control
c

Colton Idle

01/12/2022, 2:38 AM
If you just create a simple hello world app do you see the same usage on your machine?
d

David W

01/12/2022, 2:39 AM
I suppose that is the real question, for some reason it seemed like more work to do that...checking.
lol fresh project
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61
(don't try to use jdk 17)
Whatever the issue is, it's something in my app 😔
mine
empty sample app
feels like maybe something is launching a new coroutine every frame
i went through and checked all of my `launch`es
no culprits
time to start commenting out giant swathes of code, i guess
the tried and true debugging method
of the desperate
got it
val infiniteTransition = rememberInfiniteTransition()
            val angle by infiniteTransition.animateFloat(
                initialValue = 0F,
                targetValue = 360F,
                animationSpec = infiniteRepeatable(
                    animation = tween(1000, easing = FastOutLinearInEasing)
                )
            )

            Icon(
                painter = painterResource("refresh.svg"),
                modifier = Modifier
                    .graphicsLayer {
                        if (areModsLoading) {
                            rotationZ = angle
                        }
                    },
                contentDescription = "Refresh"
            )
commenting this out drops the single core usage down to relatively nothing
A graphicsLayer should be used when the content updates independently from anything above it to minimize the invalidated content.
solution:
Icon(
                painter = painterResource("refresh.svg"),
                modifier = Modifier
                    .run {
                        if (areModsLoading) {
                            val infiniteTransition = rememberInfiniteTransition()
                            val angle by infiniteTransition.animateFloat(
                                initialValue = 0F,
                                targetValue = 360F,
                                animationSpec = infiniteRepeatable(
                                    animation = tween(1000, easing = FastOutLinearInEasing)
                                )
                            )

                            this.graphicsLayer { rotationZ = angle }
                        } else this
                    },
                contentDescription = "Refresh"
            )
Before:
After:
and also single-core CPU usage went from being pegged to 10-15%
specifically, the issue was using
infiniteTransition.animateFloat
outside of the conditional that, when true, made the icon spin, which was presumably causing the area to recompose, even though the
graphicsLayer
code that used it was never called
d

Dominaezzz

01/12/2022, 1:07 PM
Hmm, if nothing is dependent on it then recomposition shouldn't happen. Hmm
c

Colton Idle

01/12/2022, 6:19 PM
Yeah. I can't say I'm following, but I'd open a bug on either compose google issuetracker or jb compose github.