-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Performance Issue : Convert Forms View to Native View(Android, iOS) (Custom Control) #4371
Comments
@Sasikumar3595 Could you explain more about what you are doing? How are you using these custom views? Are you using them in a native Android application? |
@hartez We are developed the native Android project and the project contains the structure of the Application. We are planned to moving the project to Xamarin forms and we archive it by mapping and renderer through cross platform. Also convert the Xamarin.forms view to native view , since we are converting 126 Xamarin forms view to Native Android view and it take more time(around 5 - 6 sec). |
To make sure I understand the situation: You currently have an Android application. You plan to move the application to Xamarin.Forms in the future. As part of that process, you have created some controls in Xamarin.Forms. You are using those Xamarin.Forms controls in your current Android application by converting them using the code you posted above. Is that correct? |
Yes, we are converting the Xamarin.Forms controls in to current Android application with the help of above mentioned code but it takes more time based on the complexity of Xamarin.Forms control structure. We are converting the simple structure Xamarin.Forms control such as label, button etc., its takes around 3 -4 sec. But our application, we are using complex structure such as Grid, StackLayout with two or more sub views then it takes around 6 sec. Please provide some suggestions to minimize the time delay. |
@hartez this is the Syncfusion Calendar control that takes about 6 seconds to load on Android. I think they are just wondering whether there is a more optimised/faster way of converting Xamarin.Forms views to native |
What does |
@hartez I think Something like any examples @Sasikumar3595 ? |
@hartez , The "View" refers the Xamarin Forms view such as Grid, StackLayout, Button etc., if we are using complex structure as follow snippet, the conversion of 126 forms view takes more time for convert to native Android view. Eg.,
Code Snippet for convert the Forms view to native view
|
Please submit a zipped reproduction. |
We are prepare the simple sample with view conversion from Forms to Native Android and attached below Sample : Could you please check with the above details and provide us with a possible solution for this. |
@Sasikumar3595 can you give some details about the device/api level you are testing? The gif below is from your sample and it's running on an API 23 device and it's running fairly quickly for me. |
@PureWeen, In the above attached simple sample initial conversion takes 4 sec for rendering the customized view. The below gif is from our sample on Android device with API 25 with RAM 2GB. Can you please check the same with any Android devices with same configuration (2GB RAM, not Emulator)? |
@kingces95 is this something we can plug into your profiler work to see where the waits times are occurring? |
@PureWeen That's a good idea! Let's see if we can do that next week. |
@kingces95 @PureWeen Let's get traction on this. Thanks! |
@samhouts Any update on this? |
@kingces95 can you run this through your profile stuff and see if you come up with anything on our side that we can resolve? |
Hi @samhouts, Could you please update the details on this? due to this delay, we are facing a performance issue. |
Any update on this issue? |
FYI - I'm facing the same performance-issues with Xamarin.Forms on an Android-Device (Samsung Galaxy S8) In Xamarin.Forms i've build a "Day-Cell" (that's a ContentView with a Grid in it; Vertical- and HorizontalOptions set to FillAndExpand; Just one Row/Column with a StackLayout in it containing another StackLayout with a Label an two labels underneath that StackLayout) Then i have a "MonthView" with a Grid that has 7 Columns and 6 Rows; In CodeBehind i create 42 Day-Cells and put them into the Grid to show a month Then i have a CarouselView (which is the new CollectionView) where DataTemplate is my MonthView On iOS 12 / 13 it's fine And because it's UI there seems to be no way to create such MonthView async / in a Task - Adding the Controls has to run on the MainThread of course and this seems to be very slow. FWIW: Maybe the problem here is the same - maybe it's totally different, i don't know. I just hope to be able to do a little more "complex" layout with good performance soon :) |
Yes, these layout changes need to be batched and/or some intermediate method should be available to let you inject layout changes before the native layer tries to re-layout. In the meantime, can you try using a pattern similar to the one found in https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.DualScreen/TwoPaneView.shared.cs#L290 Basically, override LayoutChildren, and only let it call base.LayoutChildren when you've completed your own layout changes. |
that's a good idea - unfortunatly that didn't help because it doesn't seem the problem (at least it's not for the Performance Problem with adding 50 ContentViews in Grid-Cells at runtime) the LayoutChildren function is called 1 or 2 times in my case - but not 50+ times (i created a CustomControl based on Grid to overload the LayoutChildren of the grid itself) - so that looks good. Meanwhile i experiment with creating a Task for each View i add to the Grid (with a small delay in the loop that's a Task on its own) Maybe that won't help too much for itself - but it could possible enable me to create a lot more MonthViews long before the user will swipe to them - so it may be possible to hide the performance issue.... not sure though because the Views should be created only if they become visible (that's how the collection view works, right?) |
Could you please update the details on this? due to this delay, we are facing a performance issue. |
To give an update for others that are finding this thread: I needed to display a Month-Calendar on a Page. With Some Numbers/Details displayed for each day. This is rediculous slow with Xamarin.Forms - unusable on Android (remember: We need to swipe thru months with a gesture, so if the user swipes, we need to build a new View and so on; And don't even think about creating 12 views before showing the page ... or you need to think about playing a Video for the User entertainment ;) ) MY SOLUTION Yes - it's hard work (calculating x/y positions of lines depending on resolution; build your own Helper-Classes to draw a Day-Cell at a specific location)
It was a lot of work but in the end i was able to solve the problem and it's WAY faster than before with XAML! (even on iOS) So: If you need to display a LOT of things on a single Page and Threading (very hard with UI controls) is not a solution (it's never - because it takes even longer... only difference: the user is not blocked completely) - Take a look at Skia and paint it your own way! :) |
Any update on this? due to this delay, we are facing a performance issue. |
@samhouts , |
@samhouts , |
Any update on this? |
Xamarin is officially End Of Life If you don't like to rewrite everything from scratch you should soon take a look at MAUI - Check if it's solved there and if not, open a new case for MAUI ... ... or if you have the chance (time, resources, ...) think about rewriting everything and take a look at Flutter - i sure has it's own problems but has a completely different approach for multi platform and is (or can be) really fast! |
To optimize performance, consider implementing asynchronous operations during conversion, breaking down complex structures into smaller tasks, and utilizing caching mechanisms to avoid redundant conversions. Additionally, explore profiling tools to identify specific bottlenecks in your conversion code. If you ever decide to expand your app to other platforms, keep in mind the potential challenges of converting iOS to Android or vice versa, and plan for platform-specific optimizations. Good luck with the optimization process! |
Description
In our custom control, we are converting the Xamarin forms view to native Android view for providing custom view, but the each of the conversion take around 0.035 sec (it increases based the complex structure of given Xamarin forms view). We are converting 126 Xamarin forms view to Native Android view so it take more time(around 5 - 6 sec). We are added the code for converting the Forms view to native view, Please provide the suggestion for this?
Basic Information
Screenshots
Not Applicable
Reproduction Link
Code Snippet for converting Xamarin forms view to Native forms view
The text was updated successfully, but these errors were encountered: