forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] improve performance of
Entry.MaxLength
Context: dotnet#10713 When investigating a customer sample: * Navigate from a Shell flyout * To a new page with several `Entry` controls When profiling on a Pixel 5, it seems one hot path is `Entry.MaxLength`: 18.52ms (0.22%) microsoft.maui!Microsoft.Maui.Platform.EditTextExtensions.UpdateMaxLength(Android.Widget.EditText,Microsoft.Maui.IEntry) 16.03ms (0.19%) microsoft.maui!Microsoft.Maui.Platform.EditTextExtensions.UpdateMaxLength(Android.Widget.EditText,int) 12.16ms (0.14%) microsoft.maui!Microsoft.Maui.Platform.EditTextExtensions.SetLengthFilter(Android.Widget.EditText,int) * `EditTextExtensions.UpdateMaxLength()` calls * `EditText.Text` getter and setter * `EditTextExtensions.SetLengthFilter()` calls * `EditText.Get/SetFilters()` What happens is we end up marshaling strings and `IInputFilter[]` back and forth between C# and Java for every `Entry` on the page. This seems like a prime candidate to move code from C# to Java. I tried to just port the code as-is without changing logic -- so we *should* get the exact same behavior as before. Since all `Entry`s go through this code path (even ones with a default value for `MaxLength`), this improves the performance of all `Entry` and `SearchBar` on Android. With these changes in place, the calls to `EditTextExtensions.UpdateMaxLength()` are now so fast they are missing from the trace now, saving ~19ms when navigating to this page. One note, is I found this was the recommended way to create a mutable `List<T>` from an array in Java: List<InputFilter> currentFilters = new ArrayList<>(Arrays.asList(editText.getFilters())); https://stackoverflow.com/a/11659198 Makes me appreciate C#! :)
- Loading branch information
1 parent
c096b3a
commit 846ca75
Showing
4 changed files
with
77 additions
and
35 deletions.
There are no files selected for viewing
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
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
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
Binary file not shown.