Is this normal for CfD apps? The drop is when I qu...
# compose-desktop
d
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
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
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
If you just create a simple hello world app do you see the same usage on your machine?
d
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
Copy code
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:
Copy code
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
Hmm, if nothing is dependent on it then recomposition shouldn't happen. Hmm
c
Yeah. I can't say I'm following, but I'd open a bug on either compose google issuetracker or jb compose github.