Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

WPF Slow Window Loading due to Invalid SpellChecking Dictionaries


:P
On this page:

File this one into the Mr. Murpy Loves Me category: I ran into a nasty issue yesterday with Markdown Monster, which is a WPF application. I got into trouble by innocently adding an SpellCheck.IsEnabled=true attribute to one of my text boxes on the Weblog Publishing form like this:

<TextBox TextWrapping="Wrap" Height="100"
         Text="{Binding ActivePostMetadata.Abstract}" 
         IsEnabled="{Binding IsAbstractVisible}" 
         
         SpellCheck.IsEnabled="True"  />

That's simple enough, and it works:

Spell checking in Markdown Monster's WebLog Publishing Dialog

Figure 1 - WPF Spellchecking is easy to add with a simple property on a TextBox control

Why so slow???

But... on my dev machine there was a major problem: With that code in place the simple form that contains the spell check now took 3+ seconds to load. Say what?

So I tried to track this down. I removed the spell check code and immediately the form popped up instantly. Add the spell check back in - 3+ seconds load time.

Next, I tried this on another computer - a low end convertible no less - and guess what: No slowdown even with the spell check code in place. WTF?

A quick look at the Visual Studio Profiler Analysis on my machine quickly pointed me at InitializeComponent() block of code after which the Profiler disappears into native code, so the issue is something internal to WPF.

Dictionaries, Dictionaries

It turns out WPF spell checking uses Windows dictionaries and these dictionaries are globally referenced in the registry. When I took a look at the global dictionary registration key in the registry at:

HKEY_CURRENT_USER\Software\Microsoft\Spelling\Dictionaries  
Key: _Global_

I immediately found my problem:

Global Dictionaries in the Registry

Figure 2 - Global dictionaries registered had a bunch of temporary non-existant files.

Ugh! There were about 15 temporary dictionaries referenced in this section and sure enough these were the cause of my slow down.

Once I removed all the temp dictionaries and left just the legit Office dictionary my form now just pops again immediately.

The slowdown was caused by the errant dictionaries. I'm not sure why this is so incredibly slow. Given that the files referenced don't exist, there can't be any parsing happening. I also double checked to see that there weren't massive files in these folders which would make the look up really slow, but that's also not the case. Just having bad entries slows down the spell checker something fierce.

Temporary Dictionaries?

I also have no idea where these errant spell check dictionaries came from. I've been keeping an eye on this registry key and haven't seen temporary dictionaries returning. Clearly some application was writing out these files that subsequently get killed when my TMPFILES folder gets cleaned up by a daily scheduled task.

But unfortunately I have no idea which one. I'll keep an eye on this key and see if it returns after more use.

Moral of the Story

At the end of the day, if you should run into a problem with slow spell checking code - check your registry and make sure the dictionaries in use are legit.

It's definitely not something you are very likely to run into, but it's one of those strange edge cases that when they bite you, it takes a lot of time to track down. If you're unlucky enough to be bitten by this particular issue, hopefully you landed here and can fix your problem quickly - unlike me who wasted a few hours tracking this down.

... and... exit Mr. Murphy. End Act One.

this post created and published with Markdown Monster
Posted in WPF  

The Voices of Reason


 

Richard
September 26, 2017

# re: WPF Slow Window Loading due to Invalid SpellChecking Dictionaries

"The slowdown was caused by the errand dictionaries."
"I also have no idea where these errand spell check dictionaries came from."

A perfect example of why checking the spelling sometimes just isn't enough! 😃

I assume you meant "errant".

https://en.wiktionary.org/wiki/errand
https://en.wiktionary.org/wiki/errant


Rick Strahl
September 27, 2017

# re: WPF Slow Window Loading due to Invalid SpellChecking Dictionaries

@Richard - LOL - you're so right! Fixed...


alan
September 27, 2017

# re: WPF Slow Window Loading due to Invalid SpellChecking Dictionaries

Hilarious! and this one too: "File this one into the Mr. Murpy Loves Me"


Pino Carafa
February 20, 2018

# re: WPF Slow Window Loading due to Invalid SpellChecking Dictionaries

We have had issues with our customers complaining about slow loading of forms with Spell Checking for ages so I'm tellin' ya if THIS fixes OUR problem you'll be our hero 😃

Watch this space ....


Ben
May 31, 2018

# re: WPF Slow Window Loading due to Invalid SpellChecking Dictionaries

This saved my bacon. I have an app that worked perfectly fine in Windows 7, but was unusably slow in Windows 10. I at one point timed it as taking 1 minute 40 seconds per spell-check enabled textbox, on a form that might have 30+ spell-check enabled textboxes. This was the problem, and after adding some kludgey registry-cleaning code, my app works in Win10 now, thanks!


Pete
November 29, 2018

# re: WPF Slow Window Loading due to Invalid SpellChecking Dictionaries

Thanks so much for this post. I was adding spell checking to a WPF RichTextBox in our application and experienced this problem, but worse--at lead 6 seconds delay on my development system. I checked the registry as you suggested and there we around 50 invalid entries there. Now it's speedy. I just wonder if our clients will have this problem.


Blake
January 25, 2021

# re: WPF Slow Window Loading due to Invalid SpellChecking Dictionaries

I have an issue that started with .NET 5 that's made spell checking with controls unusable. Once punctuation is added the textbox begins heavily lagging, the more punctuation, the slower it goes. I ran dotTrace and narrowed it down to "System.Windows.Documents.MsSpellCheckLib.RCW+IEnumSpellingError.Next" and "System.Windows.Documents.MsSpellCheckLib.RCW+ISpellChecker.Suggest".

Fixes that work with .NET Framework 4.8 don't work with .NET 5, e.g. AppContext.SetSwitch(@"Switch.System.Windows.Controls.DoNotAugmentWordBreakingUsingSpeller", true). I was hoping it was related to the issue you had but alas, it appears to be different.


West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024