Skip to content

perf(zsh): trim redundant startup work#17

Draft
nyatinte wants to merge 5 commits intomainfrom
codex/zsh-startup-audit
Draft

perf(zsh): trim redundant startup work#17
nyatinte wants to merge 5 commits intomainfrom
codex/zsh-startup-audit

Conversation

@nyatinte
Copy link
Owner

@nyatinte nyatinte commented Mar 8, 2026

zsh の起動が重い原因を追いやすくするため、既知の Starship による Git fetch 以外の同期処理を減らしました。

  • compinit~/.zshrc と Sheldon の二重実行から 1 回に整理
  • _git-gtr の本体 source をやめて、必要な zstyle だけを先に定義
  • zsh-abbrfast-abbr-highlighting を deferred load に変更
  • Docker Desktop の初期化スクリプトは存在するときだけ読むように変更
  • 使っていない gwn ヘルパーを削除
  • 使っていない Zellij のプロジェクト起動ショートカットと専用スクリプトを削除
  • fzf のディレクトリ移動で cd 失敗時にそのまま続行しないよう修正

計測:

  • origin/main: zsh -i -c exit = 0.36s, 0.13s, 0.16s
  • codex/zsh-startup-audit: zsh -i -c exit = 0.26s, 0.09s, 0.09s
  • origin/mainzprof: compinit が 2 回、_git-gtr が約 7.69ms
  • このブランチの zprof: compinit は 1 回になり、_git-gtr は起動プロファイルから消える

検証:

  • zsh -n home/dot_zshrc home/dot_zsh.d/*.zsh home/dot_zsh.d/completions/_git-gtr
  • rg -n "zellij-new-branch-tab|Alt b|new-branch-tab" home

既知の Starship による Git fetch は今回の対象外です。

Generated by Codex (Apple Request). This PR and the commits in it were created by Codex: 0f2782f, f7cf92a, e9ea2cc, e9f69fa, d9adec8.

nyatinte added 2 commits March 8, 2026 22:12
…artup

Zsh startup was paying for duplicate compinit work and eager loading of abbr-related plugins before the first prompt appeared.

Let Sheldon own compinit, keep git-gtr completion discoverable via zstyle, defer abbr-related plugins, and only source Docker Desktop init when the script exists so interactive startup does less synchronous work.
The fzf directory picker and gwn helper assumed cd would always succeed.

Returning early avoids continuing with a stale prompt state or half-finished helper flow when the target directory no longer exists or cannot be entered.
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

このプルリクエストは、Zsh の起動パフォーマンスを向上させることを目的としています。冗長な処理の削減、プラグインの遅延ロード、および条件付きスクリプト読み込みを導入することで、起動時の負荷を軽減し、より迅速なシェル環境の立ち上げを実現します。これにより、開発者の生産性向上に貢献します。

Highlights

  • compinit の実行回数の最適化: compinit の実行を ~/.zshrc と Sheldon での二重実行から 1 回に整理しました。
  • _git-gtr の読み込み改善: _git-gtr の本体 source を削除し、必要な zstyle のみを事前に定義するように変更しました。
  • プラグインの遅延ロード: zsh-abbrfast-abbr-highlighting プラグインを遅延ロードするように設定しました。
  • Docker Desktop スクリプトの条件付き読み込み: Docker Desktop の初期化スクリプトを、ファイルが存在する場合のみ読み込むように変更しました。
  • cd コマンドのエラーハンドリング強化: fzf のディレクトリ移動 (fzf-cd-widget) と gwn コマンドで cd が失敗した場合に、それ以上処理を続行しないように修正しました。
Changelog
  • home/dot_config/sheldon/plugins.toml
    • zsh-abbr プラグインに apply = ["defer"] を追加しました。
    • fast-abbr-highlighting プラグインに apply = ["defer"] を追加しました。
  • home/dot_zsh.d/dev-tools.zsh
    • Docker Desktop の初期化スクリプト (.docker/init-zsh.sh) の読み込みを、ファイルが存在する場合のみ行うように変更しました。
  • home/dot_zsh.d/fzf.zsh
    • fzf-cd-widget 関数内の cd コマンドに || return を追加し、ディレクトリ移動失敗時のエラーハンドリングを改善しました。
  • home/dot_zsh.d/utils.zsh
    • gwn 関数内の cd コマンドに || return を追加し、ディレクトリ移動失敗時のエラーハンドリングを改善しました。
  • home/dot_zshrc
    • compinit の直接呼び出しを削除し、Sheldon 側での一回実行に任せるようにしました。
    • _git-gtr スクリプトの直接 source を削除し、git gtr の補完に必要な zstyle のみ定義するように変更しました。
Activity
  • このプルリクエストには、現時点での人間によるアクティビティ(コメント、レビューなど)はありません。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

このプルリクエストは、zshの起動パフォーマンスを向上させるための素晴らしい改善です。compinitの二重実行の解消、プラグインの遅延読み込み、不要なsourceの削減など、効果的な変更が加えられています。また、cdコマンドのエラーハンドリングを改善し、堅牢性を高めている点も評価できます。全体として、起動時間を短縮し、設定ファイルをよりクリーンにする良い変更だと思います。一つ、gwn関数に潜在的なバグを見つけましたので、レビューコメントをご確認ください。

fi
fi
git gtr new "$branch_name" --from "origin/$default_branch" && cd "$(git gtr go "$branch_name")"
git gtr new "$branch_name" --from "origin/$default_branch" && cd "$(git gtr go "$branch_name")" || return

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

cd "$(git gtr go "$branch_name")" の部分に潜在的なバグがあります。
git gtr go "$branch_name" が空文字列を返した場合、zshでは cd ""cd "$HOME" と同じ挙動になり、意図せずホームディレクトリに移動してしまいます。これは予期せぬ動作を引き起こす可能性があります。

コマンドの実行結果が空でないことを確認してから cd を実行するように修正することをお勧めします。

    git gtr new "$branch_name" --from "origin/$default_branch" && { local dir; dir="$(git gtr go "$branch_name")"; [ -n "$dir" ] && cd "$dir"; } || return

nyatinte added 3 commits March 8, 2026 23:09
The gwn wrapper is no longer used anywhere in this dotfiles setup.

Dropping it reduces dead shell code and removes a helper that still depended on git gtr state even though it is no longer part of the active workflow.
The Alt-b binding only launched a dedicated project helper script, and that shortcut is no longer part of the active workflow.

Removing the keybind together with its script keeps the Zellij config smaller and avoids carrying an unmaintained project launcher path.
The earlier safety guard returned immediately when cd failed inside fzf-cd-widget.

Resetting the prompt before returning keeps the widget behavior tidy even when the selected directory disappeared or cannot be entered.
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

Successfully merging this pull request may close these issues.

1 participant