dotnet / dotnet/wpf

Adding Custom Dictionaries to WPF controls can cause perf issues by registering the same dictionary multiple times.

Open
#3,121 5 comments 2 reactions 0 assignees View on GitHub
Bug
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

This is an adoption problem moving from Win7 to Win10
This does not repro on Win7 with the old spellcheck libraries.

when you add the same dictionary to every edit box in your app, a separate custom dictionary is registered for each one in %LocalAppData%\Temp\WPF, and causes perf issues, when we really just want all the edit boxes to use the same custom dictionary.

We can work around this issues by removing the code/xaml using WPF's custom dictionary support and instead using the Windows convention of putting in a *.dic file in %AppData%\Microsoft\Spelling with the app installer.

repro is as simple as...

private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
StackPanel stackPanel = new StackPanel();

for (int i = 0; i < 100; i++)
{
var textBox = new TextBox();
textBox.Text = "Hello World.";
SpellCheck.SetIsEnabled(textBox, true);
var dictionaries = SpellCheck.GetCustomDictionaries(textBox);
dictionaries.Add(new Uri(@"pack://application:,,,/WpfDictPerf;component/CustomDictionary.lex"));

stackPanel.Children.Add(textBox);
}

this.Content = stackPanel;
}

And this may take 30+ seconds to open.

Part of the problem is how WPF converts the *.lex file into a *.dic file for Windows.

Steps to reproduce:
=============
[WpfDictPerf.zip](https://github.com/dotnet/wpf/files/4761762/WpfDictPerf.zip)

1. Run attached WPFDictPerf
2. Open %LocalAppData%\Temp\WPF

Expected Results
===========
1. App opens as fast as if no custom dictionaries are used
2. Only one new dictionary file is created

Actual Results
=========
1. App takes many seconds longer to open
2. a duplicate *.dic file is created for each textbox (even though the same spellchecker object is used, so one dictionary file applies to all TextBoxes)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.