[android] call PlatformContentViewGroup.postInvalidate() less#24222
Merged
Conversation
Context: dotnet#23991 @chabiss's sample app is running a lot of GCs: [riodictablemaui] Explicit concurrent copying GC freed 933(127KB) AllocSpace objects, 31(4092KB) LOS objects, 49% free, 4423KB/8846KB, paused 1.328ms,169us total 33.513ms [riodictablemaui] Explicit concurrent copying GC freed 722(46KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 4581KB/9162KB, paused 1.856ms,170us total 14.835ms [riodictablemaui] Explicit concurrent copying GC freed 641(43KB) AllocSpace objects, 1(108KB) LOS objects, 49% free, 4525KB/9050KB, paused 1.420ms,176us total 14.112ms [riodictablemaui] Explicit concurrent copying GC freed 619(41KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 4579KB/9158KB, paused 1.263ms,173us total 13.825ms ... many many more lines This doesn't seem like a normal amount of GCs for a simple app like this. Attaching Android Studio's allocation profiler, I can see a significant amount of allocations at: com.microsoft.maui.PlatformContentViewGroup.setHasClip() Allocations: 35,906 Deallocations: 143 Total Count: 35,763 Shallow Size: 2,288,832 The call to `postInvalidate()` is running *a lot*, and this causes: * A layout cycle * `android.os.Message` to be allocated * etc. etc. I think we can simply check if `hasClip` has changed, and only call `postInvalidate()` if it has.
Member
Author
|
I was testing this change with a public async Task RefreshView()
{
if (this.IsRefreshing)
{
return;
}
Console.WriteLine($"RefreshView starting");
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
this.IsRefreshing = true;
PeriodicTableDataModel dataModel = await this.GetDataModelAsync();
if(dataModel != null)
{
var observable = new ObservableCollection<ElementViewModel>();
foreach(var element in dataModel.Elements)
{
observable.Add(new ElementViewModel(element));
}
this.Elements = observable;
OnPropertyChanged(nameof(Elements));
}
this.IsRefreshing = false;
sw.Stop();
Console.WriteLine($"RefreshView took {sw.ElapsedMilliseconds} ms");
}Before it was around 17 seconds debugging on a Pixel 7, with this change it's: Using dotnet/maui/main, I see some log messages like this, so there might be other things we can improve: |
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
mattleibow
approved these changes
Aug 14, 2024
albyrock87
added a commit
to albyrock87/maui
that referenced
this pull request
Sep 29, 2024
github-actions Bot
pushed a commit
to albyrock87/maui
that referenced
this pull request
Oct 10, 2024
PureWeen
pushed a commit
that referenced
this pull request
Oct 11, 2024
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Context: #23991
@chabiss's sample app is running a lot of GCs:
This doesn't seem like a normal amount of GCs for a simple app like this.
Attaching Android Studio's allocation profiler, I can see a significant amount of allocations at:
The call to
postInvalidate()is running a lot, and this causes:A layout cycle
android.os.Messageto be allocatedetc. etc.
I think we can simply check if
hasCliphas changed, and only callpostInvalidate()if it has.