Skip to content

AndroidBackend: Switch to custom container (RelativeLayout too slow)#550

Merged
stackotter merged 2 commits intomainfrom
stackotter/fix_545
May 5, 2026
Merged

AndroidBackend: Switch to custom container (RelativeLayout too slow)#550
stackotter merged 2 commits intomainfrom
stackotter/fix_545

Conversation

@stackotter
Copy link
Copy Markdown
Collaborator

RelativeLayout's onMeasure implementation has a branching factor of 2, leading to Android's measurement pass being exponential with regard to the depth of the SwiftCrossUI view hierarchy. That appears to be the cause of #545, which we found out thanks to @bbrk24's profiling earlier today.

This PR resolves the issue by switching over to a custom ViewGroup subclass for our container implementation. The new implementation is written in Kotlin because a) it's much more ergonomic interacting with Android APIs from Kotlin, and b) it reduces the number of JNI calls we have to make.

This is a draft because it seems to have broken a couple of views such as checkboxes. We may be assigning a size that is too small? I haven't looked into it yet.

RelativeLayout's onMeasure implementation has a branching factor of 2,
leading to Android's measurement pass being exponential with regard to
the depth of the SwiftCrossUI view hierarchy.
@stackotter stackotter force-pushed the stackotter/fix_545 branch from b1917e8 to 3c40e04 Compare May 5, 2026 06:17
@stackotter
Copy link
Copy Markdown
Collaborator Author

The issue with toggle buttons, switches, and checkboxes being invisible was just because those SwiftCrossUI views weren't setting the sizes of their underlying widgets. The AndroidBackend now requires that all widgets get explicitly assigned sizes, so that was causing the toggles to be rendered with a size of 0x0.

@stackotter stackotter marked this pull request as ready for review May 5, 2026 06:19
Copy link
Copy Markdown
Collaborator

@bbrk24 bbrk24 left a comment

Choose a reason for hiding this comment

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

The hiccup on my segmented picker prototype went from over four seconds to under 8ms. I'd say that's a pretty good improvement

Comment thread Sources/AndroidBackend/Kotlin/CustomContainer.kt Outdated
@stackotter stackotter merged commit 986f916 into main May 5, 2026
24 checks passed
@stackotter stackotter deleted the stackotter/fix_545 branch May 5, 2026 15:27
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