Skip to content

High cpu usage on directory change in mc with fish subshell #6763

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

Closed
olfway opened this issue Mar 17, 2020 · 8 comments
Closed

High cpu usage on directory change in mc with fish subshell #6763

olfway opened this issue Mar 17, 2020 · 8 comments
Assignees
Milestone

Comments

@olfway
Copy link

olfway commented Mar 17, 2020

I'm using fish and midnight commander from homebrew on mac

fish, version 3.1.0
TERM = xterm-256color

I removed ~/.config/fish to test with empty config

If I run mc with fish subshell and press enter multiple times on some directory fish subshell start using ~130% cpu for some time

I tried to build fish with debug symbols and get backtrace while it was using cpu:

(lldb) bt

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0x00007fff73a225be libsystem_kernel.dylib`__select + 10
    frame #1: 0x0000000105e65cf1 fish`input_event_queue_t::readb(this=0x00007fca45000a50) at input_common.cpp:78:15
    frame #2: 0x0000000105e6676a fish`input_event_queue_t::readch(this=0x00007fca45000a50) at input_common.cpp:175:20
    frame #3: 0x0000000105e55ab7 fish`inputter_t::readch(this=0x00007fca45000a50, allow_commands=true) at input.cpp:495:33
    frame #4: 0x0000000105f18e8e fish`reader_data_t::read_normal_chars(this=0x00007fca45000618, rls=0x00007ffee9fa0070) at reader.cpp:2393:61
    frame #5: 0x0000000105f1ce70 fish`reader_data_t::readline(this=0x00007fca45000618, nchars_or_0=0) at reader.cpp:3246:38
    frame #6: 0x0000000105f1da3a fish`reader_readline(nchars=0) at reader.cpp:3388:72
    frame #7: 0x0000000105f1e277 fish`read_i(parser=0x00007fca44403cf0) at reader.cpp:2281:33
    frame #8: 0x0000000105f1df26 fish`reader_read(parser=0x00007fca44403cf0, fd=0, io=0x00007ffee9fa05d8) at reader.cpp:3584:37
    frame #9: 0x0000000105c619b8 fish`main(argc=1, argv=0x00007ffee9fa07c8) at fish.cpp:494:19
    frame #10: 0x00007fff738d97fd libdyld.dylib`start + 1
    frame #11: 0x00007fff738d97fd libdyld.dylib`start + 1
@ridiculousfish ridiculousfish self-assigned this Mar 18, 2020
@ridiculousfish
Copy link
Member

Thanks for filing, I'll try to reproduce!

@ridiculousfish
Copy link
Member

What command do you run? I tried:

echo (mc)

and this resulted in "Cannot get terminal settings: Inappropriate ioctl for device (25)" but no high CPU usage.

@olfway
Copy link
Author

olfway commented Mar 18, 2020

I run it like

env SHELL=/opt/fish/bin/fish /opt/mc/bin/mc

and then move cursor on any folder and press enter 10-20 times
(so mc enters that folder and then goes back)

@krobelus
Copy link
Contributor

I can reproduce on 3.1.0. Seems to be fixed on current master, probably by e334bec.

With latest master I get around 50% CPU utilization when pressing Enter repeatedly, and around half of the time seems to be spent on UTF8 -> internal UTF32 conversion if I measured correctly. These are directories with 100-200 files. Anyway that doesn't seem harmful.

@olfway
Copy link
Author

olfway commented Mar 18, 2020

I found .local/share/fish/fish_history file which is 3.8Mb, ~100k lines

No more high cpu usage after I renamed it

@krobelus
Copy link
Contributor

@olfway great point! This was caused by autosuggestions. Apparently, mc writes commands like
cd (printf '%b' '\0057home\0057johannes\0057git\0057fish\0055shell\0057build') to the fish process, and immediately clears the command line. Note the leading space, which is why it won't be added to the history. Because it doesn't prefix-match any item in the history, fish has to search through the entire history to compute autosuggestions.

Autosuggestions are generally very useful but we can definitely disable history autosuggestion if the command line starts with a space, so this should be fixed now by 390647a.

@krobelus krobelus modified the milestones: fish 3.2.0, fish 3.1.1 Mar 21, 2020
krobelus added a commit that referenced this issue Mar 21, 2020
Currently we do not add such command lines to the history, so there
won't be a suggestion from history anyway.

Fixes #6763 which occurs because midnight commander feeds fish commands
like this one (note the leading space)

` cd (printf '%b' '\0057home\0057johannes\0057git\0057fish\0055shell\0057build')`

(cherry picked from commit 390647a)
@zanchey
Copy link
Member

zanchey commented Mar 23, 2020

Shouldn't the search ignore the leading space?

@krobelus
Copy link
Contributor

I see, it could be convenient to type a leading space and still have history autosuggestions available. Currently you'd have to type the command first with autosuggestions and then prepend the space.

Maybe there's another workaround for mc? I think we could do some minimal caching for failing autosuggestions: after a history search for autosuggestions fails, as long as subsequent edits to the command line only append to it, don't run history autosuggestion again. It'd give not that much improvement, since e334bec already kind of does that, but probably still reduces the load.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants