Ticket #4421 (new defect)
mcedit is slow at handling files with long lines (25KB+)
Reported by: | slyfox | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | Future Releases |
Component: | mcedit | Version: | 4.8.28 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Branch state: | no branch | Votes for changeset: |
Description
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;
Change History
comment:1 Changed 2 years ago by zaytsev
- Summary changed from mcedit is slow at haldling files with long likes (25KB+) to mcedit is slow at handling files with long lines (25KB+)
comment:2 Changed 2 years ago by zaytsev
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.
comment:3 Changed 2 years ago by slyfox
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.