From ee9c6d0fea45c7ace74fde9a77e70c709428e2b8 Mon Sep 17 00:00:00 2001 From: lindexi Date: Sun, 26 Sep 2021 21:03:46 +0800 Subject: [PATCH 1/4] Improve LookupContentTypeForImageUri performance in XpsFixedPageReaderWriter.cs I wrote the test demo code and I found an improvement in performance. | Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | |--------------------------------------- |----------:|---------:|----------:|-------:|------:|------:|----------:| | LookupContentTypeForImageUri | 114.17 ns | 3.096 ns | 9.130 ns | 0.0153 | - | - | 64 B | | LookupContentTypeForImageUriIgnoreCase | 40.84 ns | 0.975 ns | 2.874 ns | - | - | - | - | | LookupContentTypeForImageUri | 115.00 ns | 3.858 ns | 11.375 ns | 0.0153 | - | - | 64 B | | LookupContentTypeForImageUriIgnoreCase | 55.19 ns | 1.913 ns | 5.642 ns | - | - | - | - | | LookupContentTypeForImageUri | 84.97 ns | 1.773 ns | 3.198 ns | 0.0153 | - | - | 64 B | | LookupContentTypeForImageUriIgnoreCase | 40.82 ns | 0.869 ns | 1.099 ns | - | - | - | - | | LookupContentTypeForImageUri | 91.29 ns | 1.693 ns | 1.322 ns | 0.0153 | - | - | 64 B | | LookupContentTypeForImageUriIgnoreCase | 47.45 ns | 0.961 ns | 0.852 ns | - | - | - | - | | LookupContentTypeForImageUri | 103.35 ns | 1.876 ns | 2.234 ns | 0.0153 | - | - | 64 B | | LookupContentTypeForImageUriIgnoreCase | 58.83 ns | 1.231 ns | 1.643 ns | - | - | - | - | | LookupContentTypeForImageUri | 52.88 ns | 0.973 ns | 0.911 ns | 0.0076 | - | - | 32 B | | LookupContentTypeForImageUriIgnoreCase | 31.78 ns | 0.701 ns | 1.264 ns | - | - | - | - | | LookupContentTypeForImageUri | 65.51 ns | 1.325 ns | 1.361 ns | 0.0076 | - | - | 32 B | | LookupContentTypeForImageUriIgnoreCase | 44.33 ns | 0.949 ns | 0.841 ns | - | - | - | - | | LookupContentTypeForImageUri | 66.49 ns | 1.383 ns | 2.386 ns | 0.0076 | - | - | 32 B | | LookupContentTypeForImageUriIgnoreCase | 40.33 ns | 0.688 ns | 0.643 ns | - | - | - | - | | LookupContentTypeForImageUri | 76.48 ns | 1.560 ns | 1.669 ns | 0.0076 | - | - | 32 B | | LookupContentTypeForImageUriIgnoreCase | 47.74 ns | 1.015 ns | 1.640 ns | - | - | - | - | | LookupContentTypeForImageUri | 83.05 ns | 1.536 ns | 1.769 ns | 0.0076 | - | - | 32 B | | LookupContentTypeForImageUriIgnoreCase | 58.10 ns | 1.177 ns | 1.156 ns | - | - | - | - | Benchmark: https://github.com/lindexi/lindexi_gd/tree/983c668ea7cd308a510c043b5d2e5de74da8efe7/ColalejayJearbearlerlekere --- .../Packaging/XpsFixedPageReaderWriter.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs index af81fd485..ece7f5c71 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedPageReaderWriter.cs @@ -1867,23 +1867,22 @@ Uri imageUri ) { //Extract file extension without '.' - String path = imageUri.OriginalString; - ReadOnlySpan extension = Path.GetExtension(path).ToLower(CultureInfo.InvariantCulture).AsSpan(1); - + ReadOnlySpan path = imageUri.OriginalString.AsSpan(); + ReadOnlySpan extension = Path.GetExtension(path).Slice(1); ContentType contentType; - if (extension.Equals(XpsS0Markup.JpgExtension, StringComparison.Ordinal)) + if (extension.Equals(XpsS0Markup.JpgExtension, StringComparison.OrdinalIgnoreCase)) { - contentType = XpsS0Markup.JpgContentType; + contentType = XpsS0Markup.JpgContentType; } - else if (extension.Equals(XpsS0Markup.PngExtension, StringComparison.Ordinal)) + else if (extension.Equals(XpsS0Markup.PngExtension, StringComparison.OrdinalIgnoreCase)) { contentType = XpsS0Markup.PngContentType; } - else if (extension.Equals(XpsS0Markup.TifExtension, StringComparison.Ordinal)) + else if (extension.Equals(XpsS0Markup.TifExtension, StringComparison.OrdinalIgnoreCase)) { contentType = XpsS0Markup.TifContentType; } - else if (extension.Equals(XpsS0Markup.WdpExtension, StringComparison.Ordinal)) + else if (extension.Equals(XpsS0Markup.WdpExtension, StringComparison.OrdinalIgnoreCase)) { contentType = XpsS0Markup.WdpContentType; } @@ -1892,9 +1891,8 @@ Uri imageUri //default to PNG contentType = XpsS0Markup.PngContentType; } - return contentType; - } + } /// From 19bb64a937c8079ec36451ef11ea841f25a21db4 Mon Sep 17 00:00:00 2001 From: lindexi Date: Wed, 20 Jan 2021 09:37:46 +0800 Subject: [PATCH 2/4] Remove redundant static fields to reduce memory usage --- .../src/System.Xaml/System/Xaml/Schema/XamlTypeInvoker.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeInvoker.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeInvoker.cs index 7eedd71a9..6ad2c1a98 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeInvoker.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlTypeInvoker.cs @@ -15,7 +15,6 @@ namespace System.Xaml.Schema public class XamlTypeInvoker { private static XamlTypeInvoker s_Unknown; - private static object[] s_emptyObjectArray = Array.Empty(); private Dictionary _addMethods; internal MethodInfo EnumeratorMethod { get; set; } @@ -226,7 +225,7 @@ public virtual IEnumerator GetItems(object instance) throw new NotSupportedException(SR.Get(SRID.OnlySupportedOnCollectionsAndDictionaries)); } MethodInfo getEnumMethod = GetEnumeratorMethod(); - return (IEnumerator)SafeReflectionInvoker.InvokeMethod(getEnumMethod, instance, s_emptyObjectArray); + return (IEnumerator)SafeReflectionInvoker.InvokeMethod(getEnumMethod, instance, Array.Empty()); } // vvvvv---- Unused members. Servicing policy is to retain these anyway. -----vvvvv From e890cc67c32cee478a9dc1f3077cd0c5a1bb2a19 Mon Sep 17 00:00:00 2001 From: dipeshmsft Date: Thu, 1 Dec 2022 10:30:44 +0530 Subject: [PATCH 3/4] Tooltip Direct Manipulation Fix --- .../System/Windows/Controls/PopupControlService.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs index dafc48583..a7b9e2aba 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs @@ -484,6 +484,19 @@ private void ShowToolTip(DependencyObject o, bool fromKeyboard) SetSafeArea(_currentToolTip); } + if (!_currentToolTip.IsOpen) + { + // open the tooltip, and finish the initialization when its popup window is available. + _currentToolTip.Opened += OnToolTipOpened; + _currentToolTip.IsOpen = true; + } + else + { + // If the tooltip is already open, initialize it now. This only happens when the + // app manages the tooltip directly. + SetSafeArea(_currentToolTip); + } + CurrentToolTipTimer = new DispatcherTimer(DispatcherPriority.Normal); CurrentToolTipTimer.Interval = TimeSpan.FromMilliseconds(ToolTipService.GetShowDuration(o)); CurrentToolTipTimer.Tick += new EventHandler(OnShowDurationTimerExpired); From 26c6713ff22e799f3415b16929c53dbb10805d82 Mon Sep 17 00:00:00 2001 From: dipeshmsft Date: Thu, 2 Feb 2023 14:55:21 +0530 Subject: [PATCH 4/4] Fix GetBetweenShowDelay NRE --- .../System/Windows/Controls/PopupControlService.cs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs index a7b9e2aba..dafc48583 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs @@ -484,19 +484,6 @@ private void ShowToolTip(DependencyObject o, bool fromKeyboard) SetSafeArea(_currentToolTip); } - if (!_currentToolTip.IsOpen) - { - // open the tooltip, and finish the initialization when its popup window is available. - _currentToolTip.Opened += OnToolTipOpened; - _currentToolTip.IsOpen = true; - } - else - { - // If the tooltip is already open, initialize it now. This only happens when the - // app manages the tooltip directly. - SetSafeArea(_currentToolTip); - } - CurrentToolTipTimer = new DispatcherTimer(DispatcherPriority.Normal); CurrentToolTipTimer.Interval = TimeSpan.FromMilliseconds(ToolTipService.GetShowDuration(o)); CurrentToolTipTimer.Tick += new EventHandler(OnShowDurationTimerExpired);