Faster shell startup with shell switching
tratt.net
tratt.net
romkatv did a great write-up and benchmark within the context of zsh[0]. It's a great read.
[0] https://github.com/romkatv/zsh-bench#how-not-to-benchmark
Fish actually doesn’t write to (or directly use?) $SHELL at all, as it doesn’t consider it part of the shell’s contract to do so. At least if I’m not misremembering.
See:
https://man.archlinux.org/man/login.1
> The environment variable values for $HOME, $USER, $SHELL, $PATH, $LOGNAME, and $MAIL are set according to the appropriate fields in the password entry.
$SHELL remains "/bin/bash".
I tried with --disable-translatable-strings and got a modest speedup; --disable-multibyte failed to compile, and I didn't see any other obvious options to try.
[edit] Runs below:
$ hyperfine -N "dash -c exit"
Benchmark 1: dash -c exit
Time (mean ± σ): 0.8 ms ± 0.0 ms [User: 0.4 ms, System: 0.3 ms]
Range (min … max): 0.7 ms … 1.1 ms 3011 runs
Warning: The first benchmarking run for this command was significantly slower than the rest (1.0 ms). This could be caused by (filesystem) caches that were not filled until after the first run. You should consider using the '--warmup' option to fill those caches before the actual benchmark. Alternatively, use the '--prepare' option to clear the caches before each timing run.
$ hyperfine -N "bash -c exit"
Benchmark 1: bash -c exit
Time (mean ± σ): 4.6 ms ± 0.2 ms [User: 3.3 ms, System: 1.2 ms]
Range (min … max): 4.3 ms … 5.3 ms 596 runs
Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
$ LC_ALL=C hyperfine -N "bash -c exit"
Benchmark 1: bash -c exit
Time (mean ± σ): 1.7 ms ± 0.0 ms [User: 0.7 ms, System: 0.9 ms]
Range (min … max): 1.6 ms … 2.1 ms 1446 runs
Warning: The first benchmarking run for this command was significantly slower than the rest (2.1 ms). This could be caused by (filesystem) caches that were not filled until after the first run. You should consider using the '--warmup' option to fill those caches before the actual benchmark. Alternatively, use the '--prepare' option to clear the caches before each timing run."bash and zsh are fairly fast" - the manual page for bash (confirmed up to v5.1.8) contains "It's too big and too slow" under the BUGS section near the end of the document. The dash shell is rumored to be 4x as fast as bash for many uses.
"Both ksh and dash are too bare-bones for me to want to use them as an interactive shell" - dash can actually be compiled with full editing of the command line, but is rarely prepared in this way. While dash omits almost all features that are not in the POSIX standards, it can in fact be used well as a standards-compliant interactive shell. The Korn shell also has a much larger feature set and is the default interactive shell on commercial UNIX; the last version released by David Korn has vastly more capability and features than bash.
"exec fish" - this is a bit dangerous, in that a mistake will prevent an interactive login. To fix such a case, use SFTP to push corrections. If you really like fish, ensure that it's added to the /etc/shells file, then use the chsh command to make it your login shell.
That seems a lot, and sounds like those rumours are exactly that. When Debian switched from bash to dash as /bin/sh they saved about 5% on boot time (pre-systemd) on a slow EEE "netbook" thingy.
Maybe there are some specific usage patterns that give a 4x speed-up? I don't know. That doesn't seem to be the common case though.
That "it's too big and slow" message has been there since at least 1996 by the way, the first entry in git ("Imported from ../bash-1.14.7.tar.gz").
"The Dash shell is roughly 2-5 times more efficient than the Bash shell in terms of execution speed."
https://www.baeldung.com/linux/dash-vs-bash-performance
This is a top google search result, by no means difficult to find.
Some artificial benchmarks doesn't automatically translate to "4x as fast as bash for many uses".
Things like "500k variable assignments per second" vs. "1.8M variable assignments per second" is an insignificant and unmeasurable difference for most real-world scripts because they have dozens, hundreds, or perhaps thousands of assignments. Not millions. For most scripts the majority of time is spent launching binaries and doing whatever that external binary is doing.
Produce reasonable metrics, or concede defeat.
Run "time bash script.sh" and "time dash script.sh"
Will it run 4× faster?
Almost certainly not.
It's that simple.
Ubuntu/Debian boot times are the solid proof of dash performance.
Sufficient proof is before you, and I receive your concession magnanimously.
I no longer believe you are engaging in good faith. Good day.
https://github.com/ksh93/ksh/releases
The independent pdksh spawned mksh, which is the default shell used in Android (as it has a BSD license); mksh appears to be very much active.
http://www.mirbsd.org/mksh.htm [https site has cert problems]
OpenBSD also forked oksh from pdksh. This is certainly well-maintained.
I use ksh93 as my primary shell, interactively and for personal scripts. For scripting, a killer feature is the declarative `getopts` that makes it trivial for even the quickest dirtiest script to have full command line option handling including help.
I really wish I had the link, but I lost it. I have looked for it many times but without luck. Looking again but I doubt I will find it. If I do I will update this post.
I believe this is the link, but I cannot get to it due to some cloud ways error.
https://forum.archlabslinux.com/t/interactive-shells-a-compa...