From d8559b97499cfa979f9a28d44d05ae6fdf7e914a Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Mon, 15 Aug 2016 05:30:18 +0000 Subject: [PATCH] Workaround for performance issue with `conda.txt` The performance issue must be caused by too many I/O requests to `conda.txt` from fgrep. This inline expansion should work to reduce # of read to the `conda.txt`. original performance: ``` % git rev-parse HEAD 4f76be6a129a7281a41780783eefdab3ec472a40 % time bash -c 'pyenv rehash' bash -c 'pyenv rehash' 0.05s user 0.02s system 76% cpu 0.089 total ``` previous commit: ==> 4x slower than original ``` % git rev-parse HEAD 4469d51ef7bb3e2907f5a363bb97d92896628527 % time bash -c 'pyenv rehash' bash -c 'pyenv rehash' 0.06s user 0.03s system 25% cpu 0.358 total ``` with this workaround: ==> almost same as original ``` % git rev-parse HEAD 3ffe91bdbc69220eaecf6e2088229cc27366c3f3 % time bash -c 'pyenv rehash' bash -c 'pyenv rehash' 0.05s user 0.00s system 68% cpu 0.082 total ``` --- pyenv.d/rehash/conda.bash | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pyenv.d/rehash/conda.bash b/pyenv.d/rehash/conda.bash index 9af7d0ee..a7ecf4ea 100644 --- a/pyenv.d/rehash/conda.bash +++ b/pyenv.d/rehash/conda.bash @@ -11,9 +11,13 @@ conda_exists() { [ -n "${condas}" ] } -conda_shim() { - sed -e 's/#.*//' "${BASH_SOURCE%/*}/conda.txt" | fgrep -q -x "${1##*/}" -} +shims=() +for shim in $(cat "${BASH_SOURCE%/*}/conda.txt"); do + if [ -n "${shim%%#*}" ]; then + shims[${#shims[*]}]="${shim})return 0;;" + fi +done +eval "conda_shim(){ case \"\$1\" in ${shims[@]} *)return 1;;esac;}" # override `make_shims` to avoid conflict between pyenv-virtualenv's `envs.bash` # https://github.com/yyuu/pyenv-virtualenv/blob/v20160716/etc/pyenv.d/rehash/envs.bash