notepad4 icon indicating copy to clipboard operation
notepad4 copied to clipboard

Word wrap is slow

Open 25minutes opened this issue 2 years ago • 7 comments

In latest stable version Notepad2_en_AVX2_v4.23.06r4862, word wrap is slow. For example, it takes over 5 seconds on a small 1.2MB text file (sample file attached). 1.zip

Reproduce steps:

  1. Turn off word wrap.
  2. Load the sample text file, which should complete instantly.
  3. Turn on word wrap. Notepad2 becomes unresponsive for a few seconds.

This doesn't happen on original notepad2-mod and Notepad3. On the same PC, both of them complete word wrap almost instantly.

As all these 3 editors are Scintilla based, it's a bit strange to see such a big difference.

BTW, I've already configured notepad2 to use GDI and monospaced font.

25minutes avatar Jul 27 '23 08:07 25minutes

The slow is not replaceable on my system. you can configure Notepad2 to use Direct2D or different wrap mode (default "Automatic word wrap" is the slowest one) to speedup word wrap.

zufuliu avatar Jul 27 '23 11:07 zufuliu

The slow is not replaceable on my system.

Reproduced when using "2nd Text File", works fine with "Text File" scheme.

zufuliu avatar Jul 27 '23 11:07 zufuliu

Thanks for the quick response.

I've changed wrap mode to "wrap text between words" but the issue persists. Direct2D doesn't help either, and if possible, I'd prefer to keep using GDI because one of my PC is still Windows 7 and Direct2D doesn't work well.

I'm always using the default "Text File" scheme. I though "2nd Text File" is simply a set with different font/color settings. Would it affect word wrap function?

I attach my Notepad2.ini for your reference. You might need change font because Monaco monospaced font isn't system default. Notepad2.zip

25minutes avatar Jul 27 '23 12:07 25minutes

The slow is caused by wrap all lines in one go: https://github.com/zufuliu/notepad2/blob/95a5f62a62933e4759daa1cb9eb4f9ce6ef3d8bf/scintilla/src/Editor.cxx#L5542-L5548

comment out SciCall_EnsureVisible(iDocTopLine); fixed the slow: https://github.com/zufuliu/notepad2/blob/95a5f62a62933e4759daa1cb9eb4f9ce6ef3d8bf/src/Notepad2.c#L4015-L4023

zufuliu avatar Jul 27 '23 12:07 zufuliu

Awesome! You identity the root cause so quickly :)

25minutes avatar Jul 27 '23 12:07 25minutes

Fixed by 763569c9ee2470017d0e13db89d0e7f4d50a0d49. however we should really implement parallel WrapBlock() (Scintilla 5.3.4) to speedup wrap all lines. https://github.com/zufuliu/notepad2/blob/95a5f62a62933e4759daa1cb9eb4f9ce6ef3d8bf/scintilla/src/Editor.cxx#L1494-L1496

zufuliu avatar Jul 27 '23 12:07 zufuliu

Marked as breaking change: after toggle word wrap, caret maybe invisible with the change.

zufuliu avatar Jul 27 '23 22:07 zufuliu