Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mcedit is slow at handling files with long lines (25KB+) #4421

Open
mc-butler opened this issue Dec 25, 2022 · 4 comments
Open

mcedit is slow at handling files with long lines (25KB+) #4421

mc-butler opened this issue Dec 25, 2022 · 4 comments
Labels
area: mcedit mcedit, the built-in text editor prio: medium Has the potential to affect progress ver: 4.8.28 Reproducible in version 4.8.28

Comments

@mc-butler
Copy link

Important

This issue was migrated from Trac:

Origin https://midnight-commander.org/ticket/4421
Reporter slyfox (@trofi)

Initially noticed mcedit slowness when I attempted to insert with Shift+Insert a single 35KB-long line from clipboard. It took about 40 seconds to insert that tiny amount of data.

The same slowness is visible if I open mcedit in a file with long line and start adding individual symbols to the end of it (say, press down an 'a' key and rely on repeat): CPU usage grows to 100%. perf top says most of the time is spent traversing some buffers:

  26,69%  mc                      [.] edit_buffer_get_utf
  25,02%  mc                      [.] edit_move_forward3
  14,99%  mc                      [.] edit_buffer_get_byte
   9,16%  libglib-2.0.so.0.7400.3 [.] g_utf8_get_char_validated
   5,51%  libglib-2.0.so.0.7400.3 [.] g_unichar_iswide
   4,33%  mc                      [.] edit_buffer_get_bol
   1,88%  mc                      [.] g_utf8_get_char_validated@plt

It looks like appending each next char requires traversal of the line. Looks like it causes quadratic behaviour when we insert large chunks of text via clipbuffer.

$ LANG=C mc --version
GNU Midnight Commander 4.8.28
Built with GLib 2.74.3
Built with S-Lang 2.3.3 with terminfo database
Built with libssh2 1.10.0
With builtin Editor
With subshell support as default
With support for background operations
With mouse support on xterm and Linux console
With support for X11 events
With internationalization support
With multiple codepages support
With ext2fs attributes support
Virtual File Systems:
 cpiofs, tarfs, sfs, extfs, ftpfs, sftpfs, fish
Data types:
 char: 8; int: 32; long: 64; void *: 64; size_t: 64; off_t: 64;
@mc-butler
Copy link
Author

Changed by zaytsev (@zyv) on Dec 29, 2022 at 9:01 UTC (comment 1)

  • Summary changed from mcedit is slow at haldling files with long likes (25KB+) to mcedit is slow at handling files with long lines (25KB+)

@mc-butler
Copy link
Author

Changed by zaytsev (@zyv) on Dec 29, 2022 at 15:37 UTC (comment 2)

This is quite a widespread problem with text editors. I don't remember what is the current architecture of mcedit, but I guess it's line based... I'm afraid there is no easy way to fix the issue without switching to ropes or piece/gap buffers, which is of course a significant rewrite of the editor engine.

@mc-butler
Copy link
Author

Changed by slyfox (@trofi) on Dec 29, 2022 at 18:31 UTC (comment 3)

Maybe a special case of appending to the end of a line could be sped up up to constant time.

As a benchmark I added echo $(seq 1 7000) output to clipboard (33.8K) and pasted it into empty file into vim, emacs -nw, nano, gedit, geany, kwrite and mcedit.

Only mcedit took visible amount of time handling it.

@mc-butler
Copy link
Author

Changed by zaytsev (@zyv) on Dec 30, 2022 at 12:54 UTC (comment 4)

You're most welcome to give it a go ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: mcedit mcedit, the built-in text editor prio: medium Has the potential to affect progress ver: 4.8.28 Reproducible in version 4.8.28
Development

No branches or pull requests

1 participant