diff --git a/src/Compatibility/Core/src/Android/BackgroundManager.cs b/src/Compatibility/Core/src/Android/BackgroundManager.cs index f61e81817d30..e7ad88f6395e 100644 --- a/src/Compatibility/Core/src/Android/BackgroundManager.cs +++ b/src/Compatibility/Core/src/Android/BackgroundManager.cs @@ -54,7 +54,6 @@ static void UpdateBackground(AView Control, VisualElement Element) static void OnElementChanged(object sender, VisualElementChangedEventArgs e) { - Performance.Start(out string reference); if (e.OldElement != null) { e.OldElement.PropertyChanged -= OnElementPropertyChanged; @@ -67,8 +66,6 @@ static void OnElementChanged(object sender, VisualElementChangedEventArgs e) UpdateBackgroundColor(renderer?.View, renderer?.Element); UpdateBackground(renderer?.View, renderer?.Element); } - - Performance.Stop(reference); } diff --git a/src/Compatibility/Core/src/Android/FastRenderers/VisualElementRenderer.cs b/src/Compatibility/Core/src/Android/FastRenderers/VisualElementRenderer.cs index 76bd06a78cdf..66550dee5c28 100644 --- a/src/Compatibility/Core/src/Android/FastRenderers/VisualElementRenderer.cs +++ b/src/Compatibility/Core/src/Android/FastRenderers/VisualElementRenderer.cs @@ -80,7 +80,6 @@ void Dispose(bool disposing) void OnElementChanged(object sender, VisualElementChangedEventArgs e) { - Performance.Start(out string reference); if (e.OldElement != null) { e.OldElement.PropertyChanged -= OnElementPropertyChanged; @@ -94,8 +93,6 @@ void OnElementChanged(object sender, VisualElementChangedEventArgs e) } EffectUtilities.RegisterEffectControlProvider(this, e.OldElement, e.NewElement); - - Performance.Stop(reference); } void UpdateIsEnabled() diff --git a/src/Compatibility/Core/src/Android/VisualElementTracker.cs b/src/Compatibility/Core/src/Android/VisualElementTracker.cs index 7667d0f7db62..d95408844071 100644 --- a/src/Compatibility/Core/src/Android/VisualElementTracker.cs +++ b/src/Compatibility/Core/src/Android/VisualElementTracker.cs @@ -80,8 +80,6 @@ protected virtual void Dispose(bool disposing) public void UpdateLayout() { - Performance.Start(out string reference); - VisualElement view = _renderer.Element; AView aview = _renderer.View; @@ -94,9 +92,7 @@ public void UpdateLayout() if (aview is MauiViewGroup formsViewGroup) { - Performance.Start(reference, "MeasureAndLayout"); formsViewGroup.MeasureAndLayout(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.Exactly), MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.Exactly), x, y, x + width, y + height); - Performance.Stop(reference, "MeasureAndLayout"); } else if ((aview is LayoutViewGroup || aview is ContentViewGroup || aview is CoordinatorLayout || aview is FragmentContainerView) && width == 0 && height == 0) { @@ -104,21 +100,15 @@ public void UpdateLayout() } else { - Performance.Start(reference, "Measure"); aview.Measure(MeasureSpecFactory.MakeMeasureSpec(width, MeasureSpecMode.Exactly), MeasureSpecFactory.MakeMeasureSpec(height, MeasureSpecMode.Exactly)); - Performance.Stop(reference, "Measure"); - Performance.Start(reference, "Layout"); aview.Layout(x, y, x + width, y + height); - Performance.Stop(reference, "Layout"); } // We have to make sure to update the ClipBounds to match the new size of the ViewGroup UpdateClipToBounds(); UpdateClip(); - Performance.Stop(reference); - //On Width or Height changes, the anchors needs to be updated UpdateAnchorX(); UpdateAnchorY(); @@ -326,8 +316,6 @@ void UpdateIsVisible() void UpdateNativeView(object sender, EventArgs e) { - Performance.Start(out string reference); - VisualElement view = _renderer.Element; AView aview = _renderer.View; @@ -362,21 +350,15 @@ void UpdateNativeView(object sender, EventArgs e) _context.ToPixels(view.TranslationX), _context.ToPixels(view.TranslationY)); } - - Performance.Stop(reference); } [PortHandler] void UpdateOpacity() { - Performance.Start(out string reference); - VisualElement view = _renderer.Element; AView aview = _renderer.View; aview.Alpha = (float)view.Opacity; - - Performance.Stop(reference); } [PortHandler] diff --git a/src/Compatibility/Core/src/iOS/VisualElementTracker.cs b/src/Compatibility/Core/src/iOS/VisualElementTracker.cs index 4399f772dc4a..c4617517da2a 100644 --- a/src/Compatibility/Core/src/iOS/VisualElementTracker.cs +++ b/src/Compatibility/Core/src/iOS/VisualElementTracker.cs @@ -376,8 +376,6 @@ void SetElement(VisualElement oldElement, VisualElement newElement) [PortHandler("Partially ported")] void UpdateNativeControl() { - Performance.Start(out string reference); - if (_disposed) return; @@ -399,7 +397,6 @@ void UpdateNativeControl() UpdateClip(); NativeControlUpdated?.Invoke(this, EventArgs.Empty); - Performance.Stop(reference); } void UpdateClip() diff --git a/src/Controls/src/Build.Tasks/PerformanceProvider.cs b/src/Controls/src/Build.Tasks/PerformanceProvider.cs deleted file mode 100644 index c96f7ce074ac..000000000000 --- a/src/Controls/src/Build.Tasks/PerformanceProvider.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Runtime.CompilerServices; -using Microsoft.Maui.Controls.Internals; - -namespace Microsoft.Maui.Controls.Build.Tasks -{ - [Preserve(AllMembers = true)] - internal class PerformanceProvider : IPerformanceProvider - { - internal class Statistic - { - public readonly List> StartTimes = new List>(); - public int CallCount; - public long TotalTime; - public bool IsDetail; - } - - readonly Dictionary _Statistics = new(StringComparer.Ordinal); - - public Dictionary Statistics - { - get { return _Statistics; } - } - - public void Clear() - { - Statistics.Clear(); - } - - public void Start(string reference, string tag = null, [CallerFilePath] string path = null, [CallerMemberName] string member = null) - { - string id = GetId(tag, path, member); - - Statistic stats = GetStat(id); - - if (tag != null) - stats.IsDetail = true; - - stats.CallCount++; - stats.StartTimes.Add(new Tuple(reference, Stopwatch.GetTimestamp())); - } - - public void Stop(string reference, string tag = null, [CallerFilePath] string path = null, [CallerMemberName] string member = null) - { - string id = GetId(tag, path, member); - long stop = Stopwatch.GetTimestamp(); - - Statistic stats = GetStat(id); - - if (!stats.StartTimes.Any()) - return; - - long start = stats.StartTimes.Single(s => s.Item1 == reference).Item2; - stats.TotalTime += stop - start; - } - - public IEnumerable GetStats() - { - yield return "ID | Call Count | Total Time | Avg Time"; - foreach (KeyValuePair kvp in Statistics.OrderBy(kvp => kvp.Key)) - { - string key = ShortenPath(kvp.Key); - double total = TimeSpan.FromTicks(kvp.Value.TotalTime).TotalMilliseconds; - double avg = total / kvp.Value.CallCount; - yield return string.Format("{0,-80} | {1,-10} | {2,-10}ms | {3,-8}ms", key, kvp.Value.CallCount, total, avg); - } - } - - static string ShortenPath(string path) - { - int index = path.IndexOf("Microsoft.Maui.Controls."); - if (index > -1) - path = path.Substring(index + 14); - - return path; - } - - static string GetId(string tag, string path, string member) - { - return string.Format("{0}:{1}{2}", path, member, (tag != null ? "-" + tag : string.Empty)); - } - - Statistic GetStat(string id) - { - Statistic stats; - if (!Statistics.TryGetValue(id, out stats)) - { - Statistics[id] = stats = new Statistic(); - } - return stats; - } - } -} diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/CellRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/CellRenderer.cs index 1d128ea4270d..024baf63356e 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/CellRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/CellRenderer.cs @@ -58,8 +58,6 @@ public AView GetCell(Cell item, AView convertView, ViewGroup parent, Context con if (parent == null && ParentView?.Handler?.PlatformView is ViewGroup platformParent) parent = platformParent; - Performance.Start(out string reference); - if (Cell is ICellController cellController) cellController.ForceUpdateSizeRequested -= OnForceUpdateSizeRequested; @@ -99,8 +97,6 @@ public AView GetCell(Cell item, AView convertView, ViewGroup parent, Context con Cell.PropertyChanged += PropertyChangedHandler; ((ICellController)Cell).SendAppearing(); - Performance.Stop(reference); - return view; } @@ -108,8 +104,6 @@ public AView GetCell(Cell item, AView convertView, ViewGroup parent, Context con protected virtual AView GetCellCore(Cell item, AView convertView, ViewGroup parent, Context context) #pragma warning restore CS0618 // Type or member is obsolete { - Performance.Start(out string reference, "GetCellCore"); - LayoutInflater inflater = LayoutInflater.FromContext(context); const int type = global::Android.Resource.Layout.SimpleListItem1; AView view = inflater.Inflate(type, null); @@ -119,8 +113,6 @@ protected virtual AView GetCellCore(Cell item, AView convertView, ViewGroup pare textView.SetBackgroundColor(global::Android.Graphics.Color.Transparent); view.SetBackgroundColor(global::Android.Graphics.Color.Black); - Performance.Stop(reference, "GetCellCore"); - return view; } diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs index 64b9ed2c6e11..baa49ffeb4f6 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs @@ -239,8 +239,6 @@ public override AView GetView(int position, AView convertView, ViewGroup parent) Cell cell = null; #pragma warning restore CS0618 // Type or member is obsolete - Performance.Start(out string reference); - ListViewCachingStrategy cachingStrategy = Controller.CachingStrategy; var nextCellIsHeader = false; if (cachingStrategy == ListViewCachingStrategy.RetainElement || convertView == null) @@ -267,8 +265,6 @@ public override AView GetView(int position, AView convertView, ViewGroup parent) if (cell == null) { - Performance.Stop(reference); - return new AView(_context); } } @@ -353,14 +349,11 @@ public override AView GetView(int position, AView convertView, ViewGroup parent) else UnsetSelectedBackground(layout); - Performance.Stop(reference); return layout; } AView view = CellFactory.GetCell(cell, convertView, parent, _context, _listView); - Performance.Start(reference, "AddView"); - if (cellIsBeingReused) { if (convertView != view) @@ -377,8 +370,6 @@ public override AView GetView(int position, AView convertView, ViewGroup parent) } } - Performance.Stop(reference, "AddView"); - #pragma warning disable CS0618 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete bool isHeader = cell.GetIsGroupHeader, Cell>(); @@ -407,8 +398,6 @@ public override AView GetView(int position, AView convertView, ViewGroup parent) layout.ApplyTouchListenersToSpecialCells(cell); - Performance.Stop(reference); - return layout; } diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ViewCellRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ViewCellRenderer.cs index 40683245b300..69866e5542e2 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ViewCellRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ViewCellRenderer.cs @@ -18,7 +18,6 @@ public class ViewCellRenderer : CellRenderer protected override AView GetCellCore(Cell item, AView convertView, ViewGroup parent, Context context) #pragma warning restore CS0618 // Type or member is obsolete { - Performance.Start(out string reference, "GetCellCore"); #pragma warning disable CS0618 // Type or member is obsolete var cell = (ViewCell)item; #pragma warning restore CS0618 // Type or member is obsolete @@ -27,7 +26,6 @@ protected override AView GetCellCore(Cell item, AView convertView, ViewGroup par if (container is not null) { container.Update(cell); - Performance.Stop(reference, "GetCellCore"); return container; } @@ -71,8 +69,6 @@ protected override AView GetCellCore(Cell item, AView convertView, ViewGroup par var newContainer = new ViewCellContainer(context, (IPlatformViewHandler)cell.View.Handler, cell, ParentView, unevenRows, rowHeight); - Performance.Stop(reference, "GetCellCore"); - return newContainer; } @@ -213,17 +209,13 @@ public void Update(ViewCell cell) // This cell could have a handler that was used for the measure pass for the ListView height calculations //cell.View.Handler.DisconnectHandler(); - Performance.Start(out string reference); var viewHandlerType = _viewHandler.MauiContext.Handlers.GetHandlerType(cell.View.GetType()); var reflectableType = _viewHandler as System.Reflection.IReflectableType; var rendererType = reflectableType != null ? reflectableType.GetTypeInfo().AsType() : (_viewHandler != null ? _viewHandler.GetType() : typeof(System.Object)); if (_viewHandler != null && rendererType == viewHandlerType) { - Performance.Start(reference, "Reuse"); _viewCell = cell; - Performance.Start(reference, "Reuse.SetElement"); - if (_viewHandler != cell.View.Handler) { if (cell.View.Handler?.PlatformView is AView oldCellView && @@ -241,12 +233,8 @@ public void Update(ViewCell cell) AddView(_viewHandler.PlatformView); } - Performance.Stop(reference, "Reuse.SetElement"); - Invalidate(); - Performance.Stop(reference, "Reuse"); - Performance.Stop(reference); return; } @@ -265,8 +253,6 @@ public void Update(ViewCell cell) UpdateIsEnabled(); UpdateWatchForLongPress(); - - Performance.Stop(reference); } public void UpdateIsEnabled() @@ -310,8 +296,6 @@ protected override void OnLayout(bool changed, int l, int t, int r, int b) protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { - Performance.Start(out string reference); - int width = MeasureSpec.GetSize(widthMeasureSpec); int height; @@ -334,8 +318,6 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) } SetMeasuredDimension(width, height); - - Performance.Stop(reference); } bool WatchForSwipeViewTap() diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellRenderer.cs index 711522fd70d4..e934536eb5e9 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellRenderer.cs @@ -48,8 +48,6 @@ protected override UITableViewCell CreatePlatformElement() public virtual UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv) #pragma warning restore CS0618 // Type or member is obsolete { - Performance.Start(out string reference); - var tvc = reusableCell as CellTableViewCell ?? new CellTableViewCell(UITableViewCellStyle.Default, item.GetType().FullName); tvc.Cell = item; @@ -68,7 +66,6 @@ public virtual UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, SetAccessibility(tvc, item); - Performance.Stop(reference); return tvc; } diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ListViewRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ListViewRenderer.cs index 9ccb46369cba..268fdb757c75 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ListViewRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ListViewRenderer.cs @@ -1129,8 +1129,6 @@ public override UITableViewCell GetCell(UITableView tableView, NSIndexPath index #pragma warning restore CS0618 // Type or member is obsolete UITableViewCell platformCell; - Performance.Start(out string reference); - if (!_list.TryGetTarget(out var list)) return null; var cachingStrategy = list.CachingStrategy; @@ -1181,7 +1179,6 @@ public override UITableViewCell GetCell(UITableView tableView, NSIndexPath index var bgColor = tableView.IndexPathForSelectedRow != null && tableView.IndexPathForSelectedRow.Equals(indexPath) ? UIColor.Clear : DefaultBackgroundColor; SetCellBackgroundColor(platformCell, bgColor); PreserveActivityIndicatorState(cell); - Performance.Stop(reference); if (platformCell is ContextActionsCell contextActionsCell) _contextActionsCells.Add(contextActionsCell); diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ViewCellRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ViewCellRenderer.cs index 481693e65503..ee32039a79e5 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ViewCellRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ViewCellRenderer.cs @@ -21,8 +21,6 @@ public ViewCellRenderer() public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv) #pragma warning restore CS0618 // Type or member is obsolete { - Performance.Start(out string reference); - #pragma warning disable CS0618 // Type or member is obsolete var viewCell = (ViewCell)item; #pragma warning restore CS0618 // Type or member is obsolete @@ -39,7 +37,6 @@ public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, SetAccessibility(cell, item); - Performance.Stop(reference); return cell; } @@ -99,8 +96,6 @@ void ViewCellPropertyChanged(object sender, PropertyChangedEventArgs e) public override void LayoutSubviews() { - Performance.Start(out string reference); - //This sets the content views frame. base.LayoutSubviews(); @@ -121,14 +116,10 @@ public override void LayoutSubviews() var contentFrame = ContentView.Frame; handler.LayoutVirtualView(new RectangleF(0, 0, contentFrame.Width, contentFrame.Height)); } - - Performance.Stop(reference); } public override SizeF SizeThatFits(SizeF size) { - Performance.Start(out string reference); - if (!_rendererRef.TryGetTarget(out IPlatformViewHandler handler)) return base.SizeThatFits(size); @@ -144,8 +135,6 @@ public override SizeF SizeThatFits(SizeF size) // make sure to add in the separator if needed var finalheight = (float)result.Value.Height + (SupressSeparator ? 0f : 1f) / UIScreen.MainScreen.Scale; - Performance.Stop(reference); - return new SizeF(size.Width, finalheight); } @@ -197,8 +186,6 @@ IPlatformViewHandler GetNewRenderer() void UpdateCell(ViewCell cell) #pragma warning restore CS0618 // Type or member is obsolete { - Performance.Start(out string reference); - #pragma warning disable CS0618 // Type or member is obsolete if (ViewCell is ViewCell oldCell) { @@ -243,7 +230,6 @@ void UpdateCell(ViewCell cell) UpdateIsEnabled(cell.IsEnabled); cell.View.MeasureInvalidated += OnMeasureInvalidated; - Performance.Stop(reference); } void OnMeasureInvalidated(object sender, EventArgs e) diff --git a/src/Controls/src/Core/Performance.cs b/src/Controls/src/Core/Performance.cs index 4732e760cf6e..8f68e59988e0 100644 --- a/src/Controls/src/Core/Performance.cs +++ b/src/Controls/src/Core/Performance.cs @@ -7,6 +7,7 @@ namespace Microsoft.Maui.Controls.Internals { [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This type is obsolete and will be removed in a future version.", true)] public interface IPerformanceProvider { void Stop(string reference, string tag, string path, string member); @@ -16,6 +17,7 @@ public interface IPerformanceProvider /// [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("This type is obsolete and will be removed in a future version.", true)] public class Performance { static long Reference;