Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance Delay After Using z Command to Navigate Directories #84

Open
kasperschnack opened this issue Nov 7, 2023 · 6 comments
Open
Assignees

Comments

@kasperschnack
Copy link

Environment

  • OS: Mac OS 12.7.1
  • Zsh version: zsh 5.8.1 (x86_64-apple-darwin21.0)

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

  • The _zshz_update_datafile function might be inefficiently handling the update of the data file after using the z command.

Additional Information

  • The delay only occurs after having used the z functionality to navigate to a new folder, not on shell startup or when executing other commands.
  • Commenting out zshz from .zshrc seems to improve performance, indicating that the issue is likely within the zshz functionality.

Workaround Attempted

  • None yet, aside from avoiding the use of the z command, which is not a desirable long-term solution.

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 agkozak self-assigned this Nov 7, 2023
@agkozak
Copy link
Owner

agkozak commented Nov 7, 2023

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
Copy link
Author

@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
Copy link
Owner

agkozak commented Dec 7, 2023

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
Copy link

jsirex commented May 23, 2024

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
Copy link
Owner

agkozak commented May 23, 2024

@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
Copy link
Owner

agkozak commented May 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants