AndroidBackend: Switch to custom container (RelativeLayout too slow)#550
Merged
stackotter merged 2 commits intomainfrom May 5, 2026
Merged
AndroidBackend: Switch to custom container (RelativeLayout too slow)#550stackotter merged 2 commits intomainfrom
stackotter merged 2 commits intomainfrom
Conversation
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.
b1917e8 to
3c40e04
Compare
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. |
bbrk24
reviewed
May 5, 2026
Collaborator
bbrk24
left a comment
There was a problem hiding this comment.
The hiccup on my segmented picker prototype went from over four seconds to under 8ms. I'd say that's a pretty good improvement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.