Performance degradation when using Spell Checker
See original GitHub issue- .NET Framework 4.8
- Windows version: 2004 (OS Build 19041.450) (yes, it includes KB4562899)
- Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
- Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc…)? No
Problem description:
Application freezes for a few seconds when typing text into a TextBox with SpellChecker enabled.
For example, when I do Ctrl-V with a following snippet from the clipboard:
Text includes apostrophes before and after code snippet (I work with markdown text). I took the snippet from your codebase, but it does not matter what is inside apostrophes.
Actual behavior:
After Ctrl-V application freezes for a few seconds and I cannot type further text. I also observe sporadic delays when text contains words in apostrophes. When I pause application, stacktrace points (multiple times) to the code added in 751153802c4e4d06484743c351266c9831ade85d
NdrClientCall2 Unknown ObjectStublessClient C++ _ObjectStubless@0 Unknown 589966ef() Unknown [Frames below may be incorrect and/or missing, native debugger attempting to walk managed call stack] Unknown 589966ef() Unknown [Managed to Native Transition] System.Windows.Documents.MsSpellCheckLib.Extensions.ToList Unknown System.Windows.Documents.MsSpellCheckLib.SpellChecker.ComprehensiveCheckImpl Unknown System.Windows.Documents.MsSpellCheckLib.SpellChecker.ComprehensiveCheckImplWithRetries.AnonymousMethod__0 Unknown System.Windows.Documents.MsSpellCheckLib.RetryHelper.TryExecuteFunction<System.__Canon> Unknown System.Windows.Documents.MsSpellCheckLib.SpellChecker.ComprehensiveCheckImplWithRetries Unknown System.Windows.Documents.WinRTSpellerInteropExtensions.ComprehensiveGetTokens Unknown System.Windows.Documents.WinRTSpellerInterop.SpellerSentence.Segments.get Unknown System.Windows.Documents.WinRTSpellerInterop.EnumTextSegments Unknown System.Windows.Documents.Speller.SearchForWordBreaks Unknown System.Windows.Documents.Speller.ExpandToWordBreakAndContext Unknown System.Windows.Documents.Speller.ScanRange Unknown System.Windows.Documents.Speller.OnIdle Unknown
I’m not sure if it makes many different COM calls or there is a single COM call inside OnIdle which takes too long. I’m not sure if it is somehow caused by my environment. Please let me know if you need extra details. Any workaround is appreciated.
Expected behavior:
Text typing does not have delays.
Minimal repro:
It 100% reproduces on a WPF sample application in Visual Studio 2017/2019.
I can attach a full example, but I think this XAML is enough because the rest is auto-generated code.
<Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp1" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid> <TextBox x:Name="textBox" TextWrapping="Wrap" Text="TextBox" AcceptsReturn="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" SpellCheck.IsEnabled="True"/> </Grid> </Window>
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:33 (5 by maintainers)
Top GitHub Comments
We spoke with Microsoft, and they gave us an undocumented switch to set in app.config:
It seems to make the problem go away for us. I’d be interested to know what it shows in @JesikaDG’s profiling.
I’ll try to get it into the next .NET 5 servicing update. It may slip to the one after that, if the deadline is too close.
Thanks for the reminder. I hadn’t realized this was blocking .NET 5.