-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[android] port RootLayout.axml to Java #5528
Merged
Merged
Conversation
This file contains 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
hartez
approved these changes
Mar 24, 2022
@PureWeen I was wondering about this, do I need to test a Shell flyout for these changes? |
jsuarezruiz
approved these changes
Mar 24, 2022
`dotnet trace` output of `dotnet new maui` on a Pixel 5 shows: 178.32ms microsoft.maui.controls!Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.OnCreateView(Android.Views.LayoutInflater,Android.Views.ViewGroup,Android.OS.Bundle) 31.05ms mono.android!Android.Views.LayoutInflater.Inflate 16.95ms xamarin.google.android.material!Google.Android.Material.Tabs.TabLayoutMediator.Attach 7.12ms mono.android!Android.Views.View.FindViewById(int) 2.42ms xamarin.google.android.material!Google.Android.Material.Tabs.TabLayoutMediator.ITabConfigurationStrategyInvoker.n_OnConfigureTab_Lcom_google_android_material_tabs_TabLayout_Tab_I(intptr,intptr,intptr,int) 1.22ms mono.android!Android.Views.View.set_OverScrollMode(Android.Views.OverScrollMode) 1.20ms xamarin.androidx.viewpager2!AndroidX.ViewPager2.Widget.ViewPager2.set_Adapter 1.16ms xamarin.google.android.material!Google.Android.Material.Tabs.TabLayoutMediator..ctor A lot of the time spent is inflating `RootLayout.axml` and calling `FindViewById` to get views from the inflated layout. Instead, we can port this to 5 Java methods that return each of the views directly. This avoids XML parsing, as well as reduces C# to Java interop. We can also move some calls that are in C# to Java, such as: _viewPager.Id = AView.GenerateViewId(); _viewPager.Adapter = new ShellFragmentStateAdapter(shellSection, ChildFragmentManager, pagerContext); _viewPager.OverScrollMode = OverScrollMode.Never; _viewPager.RegisterOnPageChangeCallback(new ViewPagerPageChanged(this)); new TabLayoutMediator(_tablayout, _viewPager, this) .Attach(); Moving these to the Java side, will reduce ~6 interop calls from C# to Java. Lastly, I found some repeated calls to `SectionController.GetItems()` (which copies a new `ReadonlyCollection`) that we could store in a local variable instead. After these changes, `dotnet trace` output changes to: 130.29ms Microsoft.Maui.Controls!Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.OnCreateView(Android.Views.LayoutInflater,Android.Views.ViewGroup,Android.OS.Bundle) 28.47ms Microsoft.Maui!Microsoft.Maui.ViewHelper.CreateViewPager(Android.Content.Context,AndroidX.CoordinatorLayout.Widget.CoordinatorLayout,Google.Android.Material.Tabs.TabLayout,Google.Android.Material.Tabs.TabLayoutMediator/ITabConfigurationStrategy,AndroidX.ViewPager2.Adapter.FragmentStateAd 8.86ms Microsoft.Maui!Microsoft.Maui.ViewHelper.CreateTabLayout(Android.Content.Context,Google.Android.Material.AppBar.AppBarLayout,int) 5.29ms Microsoft.Maui!Microsoft.Maui.ViewHelper.CreateCoordinatorLayout(Android.Content.Context) 2.65ms Microsoft.Maui!Microsoft.Maui.ViewHelper.CreateMaterialToolbar(Android.Content.Context,Google.Android.Material.AppBar.AppBarLayout,int,int) 2.58ms Microsoft.Maui!Microsoft.Maui.ViewHelper.CreateAppBar(Android.Content.Context,int,AndroidX.CoordinatorLayout.Widget.CoordinatorLayout) Which is a ~48ms improvement for `dotnet new maui`.
397559d
to
b7a20d6
Compare
Also renamed the methods to have "Shell" in the name
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
area-controls-shell
Shell Navigation, Routes, Tabs, Flyout
fixed-in-6.0.300-rc.1
Look for this fix in 6.0.300-rc.1!
platform/android 🤖
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.
dotnet trace
output ofdotnet new maui
on a Pixel 5 shows:A lot of the time spent is inflating
RootLayout.axml
and callingFindViewById
to get views from the inflated layout.Instead, we can port this to 5 Java methods that return each of the
views directly. This avoids XML parsing, as well as reduces C# to Java
interop.
We can also move some calls that are in C# to Java, such as:
Moving these to the Java side, will reduce ~6 interop calls from C# to Java.
Lastly, I found some repeated calls to
SectionController.GetItems()
(which copies a new
ReadonlyCollection
) that we could store in alocal variable instead.
After these changes,
dotnet trace
output changes to:Which is a ~48ms improvement for
dotnet new maui
.