[Midnight Commander] #3580: Slow start because the subshell starts slow

350 views
Skip to first unread message

Ticket System

unread,
Jan 2, 2016, 6:01:59 PM1/2/16
to alexand...@gmail.com, mc-...@googlegroups.com
#3580: Slow start because the subshell starts slow
--------------------------------+-----------------------------------
Reporter: aleb | Type: enhancement
Status: new | Priority: major
Milestone: Future Releases | Component: mc-core
Version: master | Keywords: subshell
Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
--------------------------------+-----------------------------------
On my system (Archlinux, zsh with oh-my-zsh) mc starts in 4-5 seconds
which is very noticeable. When I remove ~/.zshrc, mc starts instantly.

GNU Midnight Commander 4.8.15
With subshell support as default
With support for background operations

It might worth to start the subshell on a background thread to be able to
show the main UI faster. Then a rotating dash would be displayed in the
command prompt and in Ctrl-O until the subshell is ready.

How can I help to add this enhancement?

--
Ticket URL: <http://www.midnight-commander.org/ticket/3580>
Midnight Commander <http://www.midnight-commander.org>
Midnight Development Center

Ticket System

unread,
Jan 2, 2016, 7:03:31 PM1/2/16
to alexand...@gmail.com, mc-...@googlegroups.com
#3580: Slow start because the subshell starts slow
----------------------------+---------------------------------------
Reporter: aleb | Owner:

Type: enhancement | Status: new
Priority: major | Milestone: Future Releases
Component: mc-core | Version: master
Resolution: | Keywords: subshell

Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
----------------------------+---------------------------------------

Comment (by and):

sounds like mc has trouble to detect your shell or zsh precmd_functions
are botched or zsh version is to old.

after mc start at subshell
{{{
$ echo $SHELL
$ echo $ZSH_VERSION
$ echo $precmd_functions
$ declare -f _mc_precmd
}}}

--
Ticket URL: <http://www.midnight-commander.org/ticket/3580#comment:1>

Ticket System

unread,
Jan 2, 2016, 7:46:07 PM1/2/16
to alexand...@gmail.com, mc-...@googlegroups.com
#3580: Slow start because the subshell starts slow
----------------------------+---------------------------------------
Reporter: aleb | Owner:

Type: enhancement | Status: new
Priority: major | Milestone: Future Releases
Component: mc-core | Version: master
Resolution: | Keywords: subshell

Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
----------------------------+---------------------------------------

Comment (by aleb):

After I start mc and Ctrl-O:

{{{
$ mc

$ echo $SHELL
/bin/zsh

$ echo $ZSH_VERSION
5.2

$ echo $precmd_functions
omz_termsupport_precmd _mc_precmd

$ declare -f _mc_precmd
_mc_precmd () {
pwd >&8
kill -STOP $$
}

}}}

(BTW, I found out the slow start of the shell was because of the large
~/.zsh_history file)

--
Ticket URL: <http://www.midnight-commander.org/ticket/3580#comment:2>

Ticket System

unread,
Jan 13, 2016, 3:27:02 PM1/13/16
to alexand...@gmail.com, mc-...@googlegroups.com
#3580: Slow start because the subshell starts slow
----------------------------+---------------------------------------
Reporter: aleb | Owner:

Type: enhancement | Status: new
Priority: major | Milestone: Future Releases
Component: mc-core | Version: master
Resolution: | Keywords: subshell

Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
----------------------------+---------------------------------------

Comment (by and):

that must be a huge ~/.zsh_history indeed :)

--
Ticket URL: <http://www.midnight-commander.org/ticket/3580#comment:3>

Ticket System

unread,
Mar 11, 2016, 10:48:54 PM3/11/16
to alexand...@gmail.com, mc-...@googlegroups.com
#3580: Slow start because the subshell starts slow
----------------------------+---------------------------------------
Reporter: aleb | Owner:

Type: enhancement | Status: new
Priority: major | Milestone: Future Releases
Component: mc-core | Version: master
Resolution: | Keywords: subshell

Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
----------------------------+---------------------------------------

Comment (by ag):

I've been hunting with strace for this bug. And it has been indeed already
reported. My .bash_history is 3.5M. After
{{{
mv -i ~/.bash_history ~/.bash_history.bak
}}}
mc starts promptly. Can be 3.5M considered as huge?.. At least for bash it
is so. It starts with a delay.

Using strace I've identified a couple of critical places. The following
call takes the most time:
{{{
src/subshell.c

// ...cut...

/* Set up `precmd' or equivalent for reading the subshell's CWD
*
* Attention! Never forget that these are *one-liners* even though the
concatenated
* substrings contain line breaks and indentation for better
understanding of the
* shell code. It is vital that each one-liner ends with a line feed
character ("\n" ).
*/

switch (subshell_type)
{
case BASH:
g_snprintf (precmd, sizeof (precmd),
"
PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND\n}'pwd>&%d;kill -STOP
$$'\n"
"PS1='\\u@\\h:\\w\\$ '\n", subshell_pipe[WRITE]);
break;

// ...cut...

write_all (mc_global.tty.subshell_pty, precmd, strlen (precmd)); //
<-----------------------

// ...cut...

}}}

--
Ticket URL: <http://www.midnight-commander.org/ticket/3580#comment:4>

Ticket System

unread,
Mar 12, 2016, 3:23:29 AM3/12/16
to alexand...@gmail.com, mc-...@googlegroups.com
#3580: Slow start because the subshell starts slow
----------------------------+---------------------------------------
Reporter: aleb | Owner:

Type: enhancement | Status: new
Priority: major | Milestone: Future Releases
Component: mc-core | Version: master
Resolution: | Keywords: subshell

Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
----------------------------+---------------------------------------

Comment (by zaytsev):

As you can see, all this does is to send our precmd hook to the shell,
which we need in order for the communication with subshell to work, so on
the mc side, it doesn't actually need any time at all, but rather it
blocks at the shell end.

I think you should be able to simply run it in the terminal and see how
much time does it take... (or else extract in a small stand-alone
program). I have no idea why shells don't seem to like it if they have
huge histories, but you can try to find out.

--
Ticket URL: <http://www.midnight-commander.org/ticket/3580#comment:5>

Ticket System

unread,
Mar 12, 2016, 8:51:07 AM3/12/16
to alexand...@gmail.com, mc-...@googlegroups.com, andrey...@e-mail.ua
#3580: Slow start because the subshell starts slow
----------------------------+---------------------------------------
Reporter: aleb | Owner:

Type: enhancement | Status: new
Priority: major | Milestone: Future Releases
Component: mc-core | Version: master
Resolution: | Keywords: subshell

Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
----------------------------+---------------------------------------
Changes (by ag):

* cc: andrey.gursky@… (added)


--
Ticket URL: <http://www.midnight-commander.org/ticket/3580#comment:6>

Ticket System

unread,
May 19, 2016, 2:18:31 PM5/19/16
to alexand...@gmail.com, mc-...@googlegroups.com, andrey...@e-mail.ua, balta...@gmail.com
#3580: Slow start because the subshell starts slow
----------------------------+---------------------------------------
Reporter: aleb | Owner:

Type: enhancement | Status: new
Priority: major | Milestone: Future Releases
Component: mc-core | Version: master
Resolution: | Keywords: subshell

Blocked By: | Blocking:
Branch state: no branch | Votes for changeset:
----------------------------+---------------------------------------
Changes (by balta2ar):

* cc: baltazar.bz@… (added)


--
Ticket URL: <http://www.midnight-commander.org/ticket/3580#comment:7>

Reply all
Reply to author
Forward
0 new messages