Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/actions/run-benchmark/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run Benchmark
description: Run zsh startup benchmark with hyperfine and convert results

inputs:
hm_gen:
description: Path to the home-manager generation (for PATH setup)
required: true

outputs:
result-path:
description: Path to the converted benchmark result JSON
value: benchmark-result.json

runs:
using: composite
steps:
- name: Run benchmark
shell: bash
run: |
export PATH="${{ inputs.hm_gen }}/home-path/bin:$PATH"

hyperfine \
--warmup 10 \
--runs 50 \
--export-json bench-result.json \
'zsh -i -c exit'

- name: Convert to benchmark format
shell: bash
run: bash .github/scripts/convert-hyperfine.sh bench-result.json benchmark-result.json
62 changes: 62 additions & 0 deletions .github/actions/setup-bench-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Setup Benchmark Environment
description: Install Nix, build home-manager generation, and set up shell environment for benchmarking

outputs:
hm_gen:
description: Path to the home-manager generation
value: ${{ steps.build.outputs.hm_gen }}

runs:
using: composite
steps:
- name: Install Nix
uses: DeterminateSystems/determinate-nix-action@v3

- name: Build home-manager generation
id: build
shell: bash
run: |
HM_GEN=$(nix build --no-link --print-out-paths \
'.#darwinConfigurations.M4Pro.config.home-manager.users.mfyuu.home.activationPackage')
echo "hm_gen=$HM_GEN" >> "$GITHUB_OUTPUT"

- name: Set up shell environment
shell: bash
run: |
HM_GEN="${{ steps.build.outputs.hm_gen }}"

# Replace macOS default /etc/ files to match nix-darwin environment.
# - /etc/zprofile: remove path_helper (slow PATH construction)
# - /etc/zshrc: remove compinit/promptinit (nix-darwin sets enableGlobalCompInit=false)
# - /etc/zshenv: keep Nix daemon setup for PATH
# See hosts/common/default.nix:19-23
sudo sh -c '
echo "" > /etc/zprofile
echo "" > /etc/zshrc
'

# Create /Users/mfyuu for HISTFILE (home-manager hardcodes home.homeDirectory)
sudo mkdir -p /Users/mfyuu
sudo chown "$(whoami)" /Users/mfyuu

# Symlink user-level dotfiles
ln -sf "$HM_GEN/home-files/.zshrc" ~/.zshrc
ln -sf "$HM_GEN/home-files/.zshenv" ~/.zshenv
ln -sf "$HM_GEN/home-files/.zprofile" ~/.zprofile

# Symlink .config directories
mkdir -p ~/.config
for item in "$HM_GEN/home-files/.config/"*; do
name=$(basename "$item")
rm -rf "$HOME/.config/$name"
ln -sf "$item" "$HOME/.config/$name"
done

# Add home-manager binaries to PATH
export PATH="$HM_GEN/home-path/bin:$PATH"

# Pre-populate sheldon cache (first run clones plugins via git)
mkdir -p ~/.cache/sheldon
sheldon lock
sheldon source > ~/.cache/sheldon/sheldon.zsh
readlink ~/.config/sheldon/plugins.toml > ~/.cache/sheldon/sheldon.zsh.lock
46 changes: 46 additions & 0 deletions .github/workflows/benchmark-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Zsh Startup Benchmark (PR)

on:
pull_request:
branches: [main]

concurrency:
group: benchmark-pr-${{ github.event.pull_request.number }}
cancel-in-progress: true

permissions:
pull-requests: write

jobs:
benchmark:
name: Zsh Startup Time
runs-on: macos-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v6

- uses: ./.github/actions/setup-bench-env
id: env

- name: Disable git commit signing
run: git config --global commit.gpgsign false

- uses: ./.github/actions/run-benchmark
with:
hm_gen: ${{ steps.env.outputs.hm_gen }}

- name: Comment benchmark result on PR
uses: benchmark-action/github-action-benchmark@v1
with:
name: Zsh Startup Time
tool: customSmallerIsBetter
output-file-path: benchmark-result.json
benchmark-data-dir-path: .
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: false
save-data-file: false
alert-threshold: "150%"
comment-on-alert: true
comment-always: true
fail-on-alert: true
summary-always: true
70 changes: 5 additions & 65 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,75 +20,15 @@ jobs:
steps:
- uses: actions/checkout@v6

- name: Install Nix
uses: DeterminateSystems/determinate-nix-action@v3

- name: Build home-manager generation
id: build
run: |
HM_GEN=$(nix build --no-link --print-out-paths \
'.#darwinConfigurations.M4Pro.config.home-manager.users.mfyuu.home.activationPackage')
echo "hm_gen=$HM_GEN" >> "$GITHUB_OUTPUT"

- name: Set up shell environment
run: |
HM_GEN="${{ steps.build.outputs.hm_gen }}"

# Replace macOS default /etc/ files to match nix-darwin environment.
# - /etc/zprofile: remove path_helper (slow PATH construction)
# - /etc/zshrc: remove compinit/promptinit (nix-darwin sets enableGlobalCompInit=false)
# - /etc/zshenv: keep Nix daemon setup for PATH
# See hosts/common/default.nix:19-23
sudo sh -c '
echo "" > /etc/zprofile
echo "" > /etc/zshrc
'

# Create /Users/mfyuu for HISTFILE (home-manager hardcodes home.homeDirectory)
sudo mkdir -p /Users/mfyuu
sudo chown "$(whoami)" /Users/mfyuu

# Symlink user-level dotfiles
ln -sf "$HM_GEN/home-files/.zshrc" ~/.zshrc
ln -sf "$HM_GEN/home-files/.zshenv" ~/.zshenv
ln -sf "$HM_GEN/home-files/.zprofile" ~/.zprofile

# Symlink .config directories
mkdir -p ~/.config
for item in "$HM_GEN/home-files/.config/"*; do
name=$(basename "$item")
rm -rf "$HOME/.config/$name"
ln -sf "$item" "$HOME/.config/$name"
done

# Add home-manager binaries to PATH
export PATH="$HM_GEN/home-path/bin:$PATH"

# Pre-populate sheldon cache (first run clones plugins via git)
mkdir -p ~/.cache/sheldon
sheldon lock
sheldon source > ~/.cache/sheldon/sheldon.zsh
readlink ~/.config/sheldon/plugins.toml > ~/.cache/sheldon/sheldon.zsh.lock

# Warm up caches: cache_eval, zcompile (.zwc for sheldon.zsh)
zsh -i -c exit
- uses: ./.github/actions/setup-bench-env
id: env

- name: Disable git commit signing
run: git config --global commit.gpgsign false

- name: Run benchmark
run: |
HM_GEN="${{ steps.build.outputs.hm_gen }}"
export PATH="$HM_GEN/home-path/bin:$PATH"

hyperfine \
--warmup 10 \
--runs 50 \
--export-json bench-result.json \
'zsh -i -c exit'

- name: Convert to benchmark format
run: bash .github/scripts/convert-hyperfine.sh bench-result.json benchmark-result.json
- uses: ./.github/actions/run-benchmark
with:
hm_gen: ${{ steps.env.outputs.hm_gen }}

- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
Expand Down
31 changes: 26 additions & 5 deletions home/shell/zsh/lazy.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,32 @@ function _backward-delete-char-clear() {
zle -N _backward-delete-char-clear
bindkey '^?' _backward-delete-char-clear

autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey "^[[A" up-line-or-beginning-search
bindkey "^[[B" down-line-or-beginning-search
function _history-beginning-search-backward-end {
if [[ $BUFFER != "${_hbs_expected:-}" ]]; then
_hbs_prefix_len=$CURSOR
fi
CURSOR=$_hbs_prefix_len
zle .history-beginning-search-backward
CURSOR=$#BUFFER
_hbs_expected=$BUFFER
unset POSTDISPLAY
}
zle -N _history-beginning-search-backward-end

function _history-beginning-search-forward-end {
if [[ $BUFFER != "${_hbs_expected:-}" ]]; then
_hbs_prefix_len=$CURSOR
fi
CURSOR=$_hbs_prefix_len
zle .history-beginning-search-forward
CURSOR=$#BUFFER
_hbs_expected=$BUFFER
unset POSTDISPLAY
}
zle -N _history-beginning-search-forward-end

bindkey "^[[A" _history-beginning-search-backward-end
bindkey "^[[B" _history-beginning-search-forward-end

# custom functions
tp() {
Expand Down