zufuliu / notepad4

Notepad4 (Notepad2⨯2, Notepad2++) is a light-weight Scintilla based text editor for Windows with syntax highlighting, code folding, auto-completion and API list for many programming languages and documents, bundled with file browser plugin matepath.
Other
2.6k stars 184 forks source link

Word wrap is slow #692

Open 25minutes opened 1 year ago

25minutes commented 1 year ago

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.

zufuliu commented 1 year ago

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 commented 1 year ago

The slow is not replaceable on my system.

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

25minutes commented 1 year ago

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

zufuliu commented 1 year ago

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

25minutes commented 1 year ago

Awesome! You identity the root cause so quickly :)

zufuliu commented 1 year ago

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 commented 1 year ago

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