This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

/etc/profile optimization and correctness


Starting a login shell on my system takes a painfully long time, mostly
because fork() is pretty slow on WOW6432 systems. I've taken a look at
the shell initialization routines and identified some potential savings:

- Can't we use USERNAME to set USER instead of running `id -un`?

- Move the /tmp chmod to the user-home-directory-doesn't-exist-case, or
better yet, get rid of it altogether and move /tmp permission setting to
install scripts

- Detect the current shell by examining BASH_VERSION, ZSH_VERSION, and
so on, not by forking for the echo|tr|sed pipeline.

- Use this code to run the profile.d scripts:
saved_LC_COLLATE=$LC_COLLATE
LC_COLLATE=C
for file in /etc/profile.d/*.{sh,zsh}; do
  LC_COLLATE=$saved_LC_COLLATE
  test -a "$file" && . "$file"
done
unset saved_LC_COLLATE

- The default /etc/profile exports PS1. Please don't do that: it causes
weird issues with Emacs tramp; it causes other shells that interpret PS1
differently (like zsh) to do odd things; and it uses up precious
environment-block space. Better to set PS1 in bashrc.

- There's a useless uname -s invocation: since Cygwin doesn't run on
Windows 9x anymore (and good riddance!), the first branch of the
conditional is always taken. (Saves two forks.)

- Replace the invocation of regtool with a direct read from
/proc/registry. That is, instead of

# Three forks
PRINTER="`regtool -q get '\user\Software\Microsoft\Windows
NT\CurrentVersion\Windows\Device' | sed 's/,.*$//'`"

use

# Zero forks
read -r PRINTER <
'/proc/registry/HKEY_CURRENT_USER/Software/Microsoft/Windows
NT/CurrentVersion/Windows/Device'
export PRINTER=${PRINTER%%,*}



I've modified my own /etc/profile. It ends up being an order of
magnitude faster than the stock version:

dancol@xyzzy ~
$ time . /etc/defaults/etc/profile

real	0m1.012s
user	0m0.075s
sys	0m0.318s

dancol@xyzzy ~
$ time . /etc/profile

real	0m0.104s
user	0m0.015s
sys	0m0.015s




Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]