agkozak / zsh-z

Jump quickly to directories that you have visited "frecently." A native Zsh port of z.sh with added features.
MIT License
2.02k stars 76 forks source link

Performance Delay After Using z Command to Navigate Directories #84

Closed kasperschnack closed 5 months ago

kasperschnack commented 1 year ago

Environment

Description

A delay of 2-3 seconds occurs in the shell prompt after using the z command to navigate to a new folder. This behavior suggests that the _zshz_update_datafile function is performing an operation that is not completing promptly.

Expected Behavior

The prompt should return immediately after navigating to a new directory using the z command, without any noticeable delay.

Actual Behavior

After using the z command, there is a 2-3 second delay before the prompt reappears.

Steps to Reproduce

  1. Navigate to a new directory using the z command.
  2. Execute a simple command like echo "hello".
  3. Observe the delay before the prompt returns.

Debug Output Snippet

The debug output indicates that the _zshz_update_datafile function is being executed and is likely causing the delay: +_zshz_update_datafile:56> x=/some/path +_zshz_update_datafile:57> print -u 14 -- '/some/path|123|timestamp' ... (repeated for multiple directories) +zshz:592> return

Possible Causes

Additional Information

Workaround Attempted

Request

Guidance on how to resolve or mitigate this delay would be greatly appreciated, whether through configuration changes, optimizations, or updates to the zshz script.


Thank you for your assistance.

agkozak commented 1 year ago

Sorry to hear you're having this problem. It's one I don't think I've heard reported before. I'm sure we'll get it sorted out, though -- and thanks for reporting it.

I don't suppose you'd be willing to share your .zshrc? Sometimes that makes identifying your specific situation much easier.

kasperschnack commented 11 months ago

@agkozak thank you so much for replying! And sorry for the late response, dunno why but i didn't get a notification. My .zshrc looks like this:

# This zshrc requires you to have the following installed to be fully functional - all of which I highly recommend using:
# jq - https://stedolan.github.io/jq/
# fzf - https://github.com/junegunn/fzf
# python3.9 - https://www.python.org/downloads/
# black - https://github.com/psf/black

# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
ZSH_THEME="kolo"

plugins=(
 git
 history
 z
)

# User configuration
export EDITOR='code'

alias python="python3.10"
alias python3="python3.10"
alias pip="python3.10 -m pip"

# edit/source this file
alias ezs="$EDITOR $HOME/.zshrc"
alias szs="source $HOME/.zshrc"

# for versioning .zshrc and other files - https://www.atlassian.com/git/tutorials/dotfiles
alias dotfiles="/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME"

source $ZSH/oh-my-zsh.sh
source ~/.appsecrets

# enable fzf https://github.com/junegunn/fzf
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

# Version control of dotfiles https://dotfiles.github.io/
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
dst () {dotfiles status}
dacp () {dotfiles add -u && dotfiles commit -m "$@" && dotfiles push}

# add some convenient git shorthands
gacp () {BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) && git pull && git add . && git commit -m "$BRANCH_NAME: $@" && git push}
gacpn () {BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) && git add . && git commit -m "$BRANCH_NAME: $@" && git push --set-upstream origin $BRANCH_NAME}

# For persisting history of commands.
# For more info, please refer to https://code.visualstudio.com/remote/advancedcontainers/persist-bash-history
export PROMPT_COMMAND='history -a'
# export HISTFILE=~/commandhistory/.zsh_history # commented out because command history keeps being wiped for some wierd reason
HISTSIZE=500000
SAVEHIST=600000
setopt BANG_HIST                 # Treat the '!' character specially during expansion.
setopt EXTENDED_HISTORY          # Write the history file in the ":start:elapsed;command" format.
setopt INC_APPEND_HISTORY        # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY             # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST    # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_DUPS          # Don't record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS      # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS         # Do not display a line previously found.
setopt HIST_SAVE_NO_DUPS         # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS        # Remove superfluous blanks before recording entry.
setopt HIST_VERIFY               # Don't execute immediately upon history expansion.
setopt HIST_BEEP                 # Beep when accessing nonexistent history.

#add custom scripts to path
export PATH="$HOME/bin:/usr/bin:$PATH"

#add python stuff to path
export PATH="$HOME/Library/Python/3.10/bin:$PATH"

export OPENBLAS="$(brew --prefix openblas)"
export CFLAGS="-falign-functions=8 ${CFLAGS}"

Please let me know if there is anything else I can do to further the debugging of this issue!

agkozak commented 11 months ago

Thanks for providing your .zshrc. I don't have a Mac to test it with, but I tried it on the slowest computer I have (an old Raspberry Pi), and I could not reproduce the lag you report.

Can you do an experiment for me? Run

cd ~/.oh-my-zsh
git checkout bf7c1b16
zsh

and see if it makes a difference.

When you're done playing around with that, you can return to your original configuration using

cd ~/.oh-my-zsh
git checkout master

Thanks -- let me know how it goes.

jsirex commented 6 months ago

I noticed that this function runs every time I change directory, and it is complicated and do a lot of things multiple time.

I just did:

set -x
cd /
cd /tmp
agkozak commented 6 months ago

@jsirex Every time you press Enter at the prompt, Zsh-z reads your datafile (usually ~/.z) and updates each line in it and then writes the results back to the file. This work is absolutely necessary for the plugin to work, and the code is highly optimized -- there are minimal forks and no invocations of external utilities.

agkozak commented 6 months ago

@kasperschnack Did you try my experiment? Have you had any success?

kasperschnack commented 5 months ago

@agkozak thank you for the mention! I found out that the main cause of the slowness was actually that the git repos I was navigating to was tracking a huge bunch of files. The issues i was seeing disappeared after i made sure to maintain my .gitignore more thoroughly!

agkozak commented 5 months ago

@kasperschnack I'm glad you sorted it out. I'll close this issue.