Skip to content

Commit

Permalink
perf: decrease scheduler checks from every 1 second to 10 seconds (zd…
Browse files Browse the repository at this point in the history
…harma-continuum#409)

The scheduler is called in 10 seconds intervals when no tasks are present to lower CPU usage.

Co-authored-by: vladislav doster <10052309+vladdoster@users.noreply.github.com>
  • Loading branch information
psprint and vladdoster committed Nov 20, 2022
1 parent 1e5c0e9 commit 4938e84
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions zinit.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -2390,10 +2390,14 @@ $match[7]}:-${ZINIT[__last-formatter-code]}}}:+}}}//←→}
# (delay), i.e. "burst" allows to run package installations from
# script, not from prompt.
@zinit-scheduler() {
integer ___ret="${${ZINIT[lro-data]%:*}##*:}"
integer ___ret="${${ZINIT[lro-data]%:*}##*:}" ___secs=$(($#ZINIT_TASKS>1?1:10))
___secs=$(($#ZINIT_TASKS>1?1:10))
# lro stands for lastarg-retval-option.
[[ $1 = following ]] && sched +1 'ZINIT[lro-data]="$_:$?:${options[printexitvalue]}"; @zinit-scheduler following "${ZINIT[lro-data]%:*:*}"'
[[ -n $1 && $1 != (following*|burst) ]] && { local THEFD="$1"; zle -F "$THEFD"; exec {THEFD}<&-; }
[[ $1 = following ]] && \
sched +$___secs 'ZINIT[lro-data]="$_:$?:${options[printexitvalue]}"; @zinit-scheduler following "${ZINIT[lro-data]%:*:*}"'
(( ___secs == 10 )) && return 0
[[ -n $1 && $1 != (following*|burst) ]] && \
{ local THEFD="$1"; zle -F "$THEFD"; exec {THEFD}<&-; }
[[ $1 = burst ]] && local -h EPOCHSECONDS=$(( EPOCHSECONDS+10000 ))
ZINIT[START_TIME]="${ZINIT[START_TIME]:-$EPOCHREALTIME}"

Expand Down

0 comments on commit 4938e84

Please sign in to comment.