Spell checking is very slow in commit dialog on Windows 8 and later

Ivan Zhakov <[email protected]>
Newsgroups gmane.comp.version-control.subversion.tortoisesvn.devel
Message-ID <CAPZho0-L61PidMb5KXdR4pNU9L0rPE-dXa1hScOWBjftS0qBoA@mail.gmail.com>
I've noticed that log message spell checking is extremely slow on
Windows 8 and later.

It seems that root cause is the fact that Microsoft spell checking API
is implemented as out-of-process DCOM server [1]. TortoiseProc uses
STA apartment, so every MS Spell checking API COM call cause message
pump and WM_PAINT for Scinitilla editor is processed.

I suggest the following changes to improve spell checker performance
in commit dialog:
1. Perform styling and spell checking in SCN_STYLENEEDED notification
handler instead of SCN_MODIFIED: The code was using SCN_STYLENEEDED
before r26518 [1]. Commit r26518 justification was that
SCN_STYLENEEDED is called for every repaint. But this was happening
because we didn't update end styled position in editor. Calling
SCI_STARTSTYLING(endpos) and SCI_SETSTYLING(0) after processing
SCN_STYLENEEDED fixes this problem and editor stops sending
SCN_STYLENEEDED notification for every repaint. See attached patch.
This fixes unnecessary repaints during styling Scintilla editor seems
to be smart enough to block repaint during SCN_STYLENEEDED processing.

2. Introduce small cache for spell checker. For 1000 words or
something. We checking the same text multiple times during typing, so
this gives huge performance improvement. I've patch in progress, but
it's not ready yet.

[1] https://msdn.microsoft.com/en-us/library/windows/desktop/hh869748
[2] https://sourceforge.net/p/tortoisesvn/code/26518/

-- 
Ivan Zhakov

------------------------------------------------------
http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=757&dsMessageId=3171044

To unsubscribe from this discussion, e-mail: [[email protected]].
tsvn-spellchecker-performance-v1.patch (text/x-diff, 1.9 KB)
Index: src/Utils/MiscUI/SciEdit.cpp
===================================================================
--- src/Utils/MiscUI/SciEdit.cpp	(revision 27279)
+++ src/Utils/MiscUI/SciEdit.cpp	(working copy)
@@ -888,6 +888,26 @@
                 }
                 return TRUE;
             }
+        case SCN_STYLENEEDED:
+            {
+                int startpos = (int)Call(SCI_GETENDSTYLED);
+                int endpos = ((SCNotification *)lpnmhdr)->position;
+
+                int startwordpos = (int)Call(SCI_WORDSTARTPOSITION, startpos, true);
+                int endwordpos = (int)Call(SCI_WORDENDPOSITION, endpos, true);
+
+                MarkEnteredBugID(startwordpos, endwordpos);
+                if (m_bDoStyle)
+                    StyleEnteredText(startwordpos, endwordpos);
+
+                StyleURLs(startwordpos, endwordpos);
+                CheckSpelling(startwordpos, endwordpos);
+
+                // Tell scintilla editor that we styled all requested range.
+                Call(SCI_STARTSTYLING, endwordpos);
+                Call(SCI_SETSTYLING, 0, 0);
+            }
+            break;
         case SCN_MODIFIED:
             {
                 if (lpSCN->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT))
@@ -902,16 +922,7 @@
                     firstpos = min(firstpos, pos1);
                     lastpos = max(lastpos, pos2);
 
-                    MarkEnteredBugID(firstpos, lastpos);
-                    if (m_bDoStyle)
-                        StyleEnteredText(firstpos, lastpos);
-
-                    int startpos = (int)Call(SCI_WORDSTARTPOSITION, firstpos, true);
-                    int endpos = (int)Call(SCI_WORDENDPOSITION, lastpos, true);
-                    StyleURLs(startpos, endpos);
-                    CheckSpelling(startpos, endpos);
                     WrapLines(firstpos, lastpos);
-                    Call(SCI_COLOURISE, startpos, endpos);
                 }
             }
             break;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.