Skip to content

[.NET 10] Add performance logging and suggestions#29972

Closed
jsuarezruiz wants to merge 18 commits intonet10.0from
fix-28091
Closed

[.NET 10] Add performance logging and suggestions#29972
jsuarezruiz wants to merge 18 commits intonet10.0from
fix-28091

Conversation

@jsuarezruiz
Copy link
Contributor

@jsuarezruiz jsuarezruiz commented Jun 13, 2025

Description of Change

This PR includes changes to add a performance monitoring system for the .NET MAUI framework, focusing on performance metrics including layout engine performance or Image performance monitoring. The system is integrated directly into the MAUI framework, outlines a modular architecture with per-domain trackers (Layout, Image), each using its own Meter and instruments from the System.Diagnostics.Metrics API.

Available by default in Debug and Trimmed in Release although included a Feature to allow enable or disable it. If you want to get performance metrics in Release mode, can enable the profiling:

dotnet build -c Release -p:EnableMauiPerformanceMonitoring=true

NOTE: This feature is still under development, created this PR to provide visibility and early feedback.

How to use:

First, add the performance monitoring and configure it in the MauiProgram.cs file.

appBuilder.AddPerformanceMonitoring(options =>
{
 options.ConfigureImage(image =>
 {
 	image.EnableLoadTimeTracking = true;
 });

 options.ConfigureLayout(layout =>
 {
 	layout.EnableMeasurePassTracking = true;
 	layout.EnableArrangePassTracking = true;
 	layout.TrackPerElement = true;
 });

 options.ConfigureWarnings(warning =>
 {
 	warning.Enable = true;
 	warning.MinimumLevel = PerformanceWarningLevel.Info;
 	warning.Thresholds = new PerformanceThresholds
 	{
 		Image = new ImageThresholds
 		{
 			ImageMaxLoadTime = TimeSpan.FromMilliseconds(100),
 		},
 		Layout = new LayoutThresholds
 		{
 			LayoutMaxArrangeTime = TimeSpan.FromMilliseconds(1),
 			LayoutMaxMeasureTime = TimeSpan.FromMilliseconds(2)
 		}
 	};
 });
});

There are parameters to activate/deactivate metrics and thresholds to obtain warnings or recommendations if we exceed them.

Then, can get stats by requests:
var layoutStats = _performanceProfiler.Layout.GetStats();

Updates in realtime:
performanceProfiler.Layout.SubscribeToLayoutUpdates(OnLayoutUpdate);

And also, we can get warnings:
performanceProfiler.Warnings.WarningRaised += OnPerformanceWarning;

More details: #28091 (comment)

A simplified version is available here main...fix-28091-II
Not have options parameters, warnings, options to subscribe to get stats at realtime etc.

Issues Fixed

Fixes #28091

@jsuarezruiz jsuarezruiz added the t/enhancement ☀️ New feature or request label Jun 13, 2025
@jsuarezruiz jsuarezruiz added the perf/general The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf) label Jun 13, 2025
@@ -0,0 +1,109 @@
#nullable disable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to enable it for new class?

@jsuarezruiz
Copy link
Contributor Author

Closed to put the focus on #30130
We will apply in upcoming PR changes from here.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

perf/general The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf) t/enhancement ☀️ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants