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.
Context: dotnet#18505 Context: https://github.com/dotnet/maui/files/13251041/MauiCollectionView.zip Context: dotnet#21229 (review) In profiling scrolling of an app with a `<CollectionView/>` and 12 `<Label/>`s, we see time spent in: 1.9% Microsoft.Maui!Microsoft.Maui.Platform.MauiTextView.OnLayout(bool,int,int,int,int) This is a callback from Java to C#, which has a performance cost. Reviewing the code, we would only need to make this callback *at all* if `Label.FormattedText` is not `null`. The bulk of all `Label`'s can avoid this call? To do this: * Write a new `PlatformAppCompatTextView.java` that override `onLayout()` * It only calls `onLayoutFormatted()` if a `isFormatted` `boolean` field is `true` * We can set `isFormatted` if a formatted string is such as: `isFormatted = !(text instanceof String)` With this change in place, the above `MauiTextView.OnLayout()` call is completely gone from `dotnet-trace` output. Scrolling the sample also "feels" a bit snappier. This should improve the performance of all non-formatted `Label`s on Android. This is the mininum amount of API changes possible -- which seems like what we should go for if we ship this change in .NET 8 servicing.
- Loading branch information
1 parent
705b551
commit 83960b0
Showing
6 changed files
with
57 additions
and
8 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformAppCompatTextView.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.microsoft.maui; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.widget.AppCompatTextView; | ||
|
||
public class PlatformAppCompatTextView extends AppCompatTextView { | ||
public PlatformAppCompatTextView(@NonNull Context context) { | ||
super(context); | ||
} | ||
|
||
private boolean isFormatted; | ||
|
||
/** | ||
* Sets isFormatted=true, used for FormattedString content | ||
* @param text | ||
* @param type | ||
*/ | ||
@Override | ||
public void setText(CharSequence text, BufferType type) { | ||
isFormatted = !(text instanceof String); | ||
super.setText(text, type); | ||
} | ||
|
||
@Override | ||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) { | ||
super.onLayout(changed, left, top, right, bottom); | ||
|
||
if (isFormatted) { | ||
onLayoutFormatted(changed, left, top, right, bottom); | ||
} | ||
} | ||
|
||
/** | ||
* To be overridden from C# | ||
* @param changed | ||
* @param left | ||
* @param top | ||
* @param right | ||
* @param bottom | ||
*/ | ||
protected void onLayoutFormatted(boolean changed, int left, int top, int right, int bottom) { } | ||
} |
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
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.