Powerlevel9k / powerlevel9k

Powerlevel9k was a tool for building a beautiful and highly functional CLI, customized for you. P9k had a substantial impact on CLI UX, and its legacy is now continued by P10k.
https://github.com/romkatv/powerlevel10k
MIT License
13.46k stars 949 forks source link

[Performance] startup time increases dramatically on branch "next" #1324

Open laggardkernel opened 5 years ago

laggardkernel commented 5 years ago

Just noticed the startup time increased dramatically on branch "next" compared with branch "master".

branch default conf 0 segment
master 40 ms 35 ms
next 476 ms 71 ms

The above result is got from plugin manager zplugin and bytecode compiling is used for each zsh file. Tested on my laptop with an SSD. There's a perceptible delay on prompt's first rendering.

After some digging, I find out the overhead is caused by the anonymous function within each segment, mainly the p9k::register_segment calls.

TIMEFMT=$'real %E user %U sys %S  cpu %P total %*E'

time (p9k::register_segment "DIR" 'DEFAULT' "blue" "$DEFAULT_COLOR" '' $'\uE818' $'\uF115' '\u'${CODEPOINT_OF_AWESOME_FOLDER_O} $'\uF115')
0.01s user 0.01s system 98% cpu 0.023 total

time (p9k::set_default P9K_DIR_PATH_SEPARATOR "/")
0.00s user 0.00s system 72% cpu 0.002 total

Causes of the problem

xtrace result of `p9k::register_segment`