Skip to content

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

@mc-butler

Description

@mc-butler

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: mceditmcedit, the built-in text editorprio: mediumHas the potential to affect progressver: 4.8.28Reproducible in version 4.8.28

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions