Improve performance
Hi, Thanks for this, I couldn't quite get powerline itself to work in my setup so this is handy.
Where I work the git repo is really big so each git command takes about 0.3 seconds.
As there a few it takes about a second to draw for the prompt to draw.
I don't know git well enough to provide a patch, but I was looking at whether its possible to get more of the stats using fewer external commands,
As an experiment I've made a script that gets the changed file count, and the the amount of insertions, using one call to git diff --shortstat and then parsing the output in bash.
Maybe this would be useful in helping speed up rendering of the prompt?
$ ./parse_git_stats.sh
original output: " 3 files changed"
changed: '3'
inserted: '4'
script:
#!/bin/bash
# Set comma as the delimiter
IFS=','
read -a gitstat <<< $(git diff --shortstat)
# Example output from git diff --shortstat:
# 3 files changed, 4 insertions(+)
#
# read has split it by comma, next remove space prefix and text suffix
# using bash.
git_changed=${gitstat[0]%" files changed"}
git_changed=${git_changed# }
git_insertions=${gitstat[1]% "insertions(+)"}
git_insertions=${git_insertions# }
echo "changed: '"$git_changed"'"
echo "inserted: '"$git_insertions"'"
Most of the work is removing the prefixes + suffixes from the strings.
Hi, You can benchmark the segments by editing __powerline_prompt_command to output how long each one takes:
function __powerline_prompt_command {
local last_status="$?" ## always the first
local separator_char="${POWERLINE_PROMPT_CHAR}"
LEFT_PROMPT=""
SEGMENTS_AT_LEFT=0
LAST_SEGMENT_COLOR=""
TIMEFORMAT=%R
## left prompt ##
for segment in $POWERLINE_PROMPT; do
local f="__powerline_${segment}_prompt"
#local info="$(__powerline_${segment}_prompt)"
echo -ne "$segment: "
time local info="$($f)"
[[ -n "${info}" ]] && __powerline_left_segment "${info}"
done
[[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(__color - ${LAST_SEGMENT_COLOR})${separator_char}$(__color)"
PS1="${LEFT_PROMPT} "
## cleanup ##
unset LAST_SEGMENT_COLOR \
LEFT_PROMPT \
SEGMENTS_AT_LEFT
}
Then re-run .bashrc:
source ~/.bashrc
And get timing output:
/.bash/themes/git_bash_windows_powerline> > master>>
last_status: 0.389
user_info: 0.069
cwd: 0.069
scm: 2.744
There a few possible avenues for optimisation, but having timing information makes it much easier.
Based on this, I've made an easy performance fix for last_status.
https://github.com/diesire/git_bash_windows_powerline/pull/3