[PATCH] vars.sh: remove unnecessary fork to speedup boot/upgrades

Adam Borowski kilobyte at angband.pl
Wed Sep 2 13:40:09 BST 2020

On Tue, Sep 01, 2020 at 08:41:38PM +0200, Trek wrote:
> Thorsten Glaser <t.glaser at tarent.de> wrote:
> > On Mon, 31 Aug 2020, Adam Borowski wrote:
> > > I don't think we should throw away a significant (10% w/o color /
> > > 5% with) speed-up just because of a bug _somewhere else_.  
> > 
> > But I found something to possibly work around both this bug and
> > the speed penalisation depending on shell implementation.

> revision		dash	mksh	bash
> -----------------------+-------+-------+-----
> patch1-10		100.0	132.7	201.0
> fancy			328.3	413.4

> fancy output is really slow, mostly because it forks many tput and some
> echo, here the execve list when starting a service with the
> debian/master version and dash

It's pointless to use tput.  It uses assumptions that made sense many
decades ago, but do more ill than good nowadays (eg. on a serial console).
The TERM variable is of no use as terminal/OS vendors stopped updating
their termcap databases by mid-1980s as every terminal switched to vt100ish
commands that have a good enough baseline and cleanly ignore extensions.

Thus, most new programs simply hardcode the color codes.  Even no-color
terminals (last I've seen are Win98's telnet.exe and something on last
millenium VMS) gracefully skip them, possibly supporting bold (\e[1m).

So, let's do this:
    if [ -t 1 ]; then
        printf '\e[31mRED \e[32;1mLIGHT GREEN\e[0m\n'
        printf 'monochromatic\n'

Ie, if isatty(1) say we're on a terminal, we can use fancy color.

The syntax is: \e [ ;-separated-commands m

A very paranoid list of supported commands, as of turn of the millenium:
    0    reset
    1    bright/bold
    31	 red
    32   green
    33   brown/yellow
    34   blue
    35   magenta
    36   cyan
    37   white
Any sane terminal from last decades can do much more, but we want to be
safe on Cisco Java SuperHiperBrokenTerm.

And hey, lookie here:

The former doesn't even check isatty(), the latter uses codes that don't
work on Hurd console or Linux < 3.16 (where I implemented them myself :) ).

⢿⡄⠘⠷⠚⠋⠀ It's time to migrate your Imaginary Protocol from version 4i to 6i.

More information about the Debian-init-diversity mailing list