Skip to content

Perf: : fzf-tab Integration & Zsh Optimization#9

Merged
0xdilshan merged 6 commits into
mainfrom
perf
Feb 24, 2026
Merged

Perf: : fzf-tab Integration & Zsh Optimization#9
0xdilshan merged 6 commits into
mainfrom
perf

Conversation

@0xdilshan

@0xdilshan 0xdilshan commented Feb 24, 2026

Copy link
Copy Markdown
Owner

This PR introduces fzf-tab to modernize the shell completion experience and implements zcompile logic to ensure the configuration remains snappy despite the added functionality.

🛠 Key Changes

  • Integrated fzf-tab: Replaces the clunky default Zsh completion menu with a modern, fuzzy-searchable interface. This allows for lightning-fast filtering of completions directly via fzf.
  • Bytecode Compilation (zcompile): Optimized startup times by automatically compiling high-traffic scripts and the new fzf-tab module into .zwc files.
  • Documentation Refresher:
    • Updated the Modern CLI Arsenal list to include fzf-tab.
    • Refreshed benchmark results to reflect the performance impact of these changes (ensuring the added features don't compromise startup speed).

📊 Benchmark Results

Note

Total startup time remains highly optimized thanks to the zcompile implementation. The docs have been updated to reflect the new sub-second load times.


🧪 How to Test

  1. Pull this branch: git checkout perf/fzf-tab-optimization
  2. Restart your shell or run source ~/.zshrc.
  3. Test the new UI: Type cd [TAB] or git checkout [TAB] to see the fuzzy-searchable completion menu.
  4. Verify optimization: Check for generated .zwc files in the plugin directory to confirm zcompile is working.

Generated by the 0xdilshan performance & docs initiative.

Summary by CodeRabbit

  • New Features

    • Added fzf-tab for richer tab-completion, previews and grouping; reorganized load order for completions, highlighting, and autosuggestions.
    • Added FZF defaults for file-finding commands.
  • Performance Improvements

    • Improved startup and input lag benchmarks (~70ms startup, ~3ms input lag).
  • Reliability

    • Increased shell history capacity and smarter history behaviors (share, append, ignore dups/space, verify, reduce blanks, auto-cd).
    • Automatic byte-compilation of startup config for more reliable loading.
  • Documentation

    • Updated README and benchmark imagery.

@coderabbitai

coderabbitai Bot commented Feb 24, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Reorders plugin and completion loading in .zshrc, adds and configures fzf-tab, adjusts completions/highlighting/autosuggestions order, increases history limits, defines FZF fd-based commands, switches to terminfo keybindings, and adds an auto_compile step to produce ~/.zshrc.zwc. README badges and benchmarks updated.

Changes

Cohort / File(s) Summary
Shell Configuration
\.zshrc
Reworks plugin/completion load order; adds and configures fzf-tab (descriptions, cd preview, group switching, FZF-Tab styling); moves completions before highlighting and autosuggestions last; increases HISTSIZE/SAVEHIST; adds PATH deduplication and history options; sets FZF_DEFAULT_COMMAND / FZF_CTRL_T_COMMAND using fd; switches to terminfo-based up/down keybindings; adds auto_compile to byte-compile ~/.zshrc and optionally handle local customizations (~/.zshrc.local).
Documentation
README.md
Updates performance badges and hero claim (<100ms → <70ms), adds fzf-tab to completion list, updates benchmark numbers (First Prompt ~98ms → ~69ms; Command Lag ~100ms → ~70ms; Input Lag 6ms → ~3ms) and references a benchmark image.

Sequence Diagram(s)

sequenceDiagram
    participant User as "User Shell"
    participant Zinit as "Plugin Loader (zinit)"
    participant FzfTab as "fzf-tab"
    participant Completion as "Completion System"
    participant Highlight as "Syntax Highlighting"
    participant Zcompile as "auto_compile / zcompile"

    User->>Zinit: start shell -> load plugins
    Zinit->>Completion: initialize completions (fzf-tab registered)
    Completion->>FzfTab: provide completion UI & cd preview
    Zinit->>Highlight: load syntax highlighting (after completions)
    User->>Zcompile: auto_compile checks/creates ~/.zshrc.zwc
    Zcompile-->>User: compiled config or fallback to sourcing
    FzfTab-->>User: offer completions/previews
    Highlight-->>User: provide syntax highlighting
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I hop through configs, compile with care,

I stitch fzf-tab's bright, descriptive flair,
History deepens, paths trimmed neat,
Completions hum, prompts quick and sweet,
A dotted trail of shell-time cheer.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: introducing fzf-tab completion integration and optimizing Zsh with zcompile bytecode compilation, history improvements, and keybinding refinements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch perf

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.zshrc:
- Around line 110-116: The fzf-tab preview command uses an unquoted $realpath
which breaks on paths with spaces; update the zstyle entry for
':fzf-tab:complete:cd:*' fzf-preview so the path expansion is quoted (i.e.,
ensure $realpath is wrapped in double quotes inside the fzf-preview string) so
eza receives the full path correctly and won’t treat parts as flags or separate
args.

In `@README.md`:
- Line 35: The header badges still show "<100ms" startup and "~6ms" input lag
which conflicts with the new 70ms/3ms targets; locate the top header badges (the
badge images/alt/title text that contain "<100ms" and "~6ms") and update their
labels and any shields.io query parameters or alt/title attributes to reflect
the new "≤70ms startup" and "≈3ms input lag" values so the visual badges and
underlying links match the README's updated claim.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ec5ddb and bb51847.

📒 Files selected for processing (3)
  • .zshrc
  • README.md
  • benchmark/z-shift-bench.webp

Comment thread .zshrc
Comment thread README.md

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.zshrc:
- Around line 229-234: The snippet hardcodes $HOME when checking/compiling the
zsh byte-compiled file (.zshrc.zwc) and should respect a custom ZDOTDIR; update
the logic that references "$HOME/.zshrc" and "$HOME/.zshrc.zwc" to compute the
dotfile path using ${ZDOTDIR:-$HOME} (or a variable like dotdir) so checks and
the zcompile invocation use "${dotdir}/.zshrc" and "${dotdir}/.zshrc.zwc"
instead; apply the same change to the other occurrences mentioned (lines
handling the .zshrc/.zshrc.local paths) and keep the zcompile "$.../.zshrc" call
consistent with the new dotdir variable.
- Around line 76-83: The compdump compile command currently hardcodes
~/.zcompdump; update the zinit atload/atinit block that runs
zicompinit/zicdreplay and the zcompile invocation to respect ZSH_COMPDUMP and
ZDOTDIR by using the computed compdump path (e.g.,
${ZSH_COMPDUMP:-${ZDOTDIR:-$HOME}/.zcompdump}) instead of ~/.zcompdump so
zcompile targets the actual dump file used by the environment; adjust the
conditional that checks modification time to use that same computed variable and
keep the zicompinit/zicdreplay calls intact.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb51847 and 840171f.

📒 Files selected for processing (2)
  • .zshrc
  • README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md

Comment thread .zshrc Outdated
Comment thread .zshrc Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
.zshrc (1)

75-77: ⚠️ Potential issue | 🟡 Minor

~/.zcompdump still hardcoded in the atload hook.

This was flagged in a previous review and remains unresolved. The atload hook should resolve the compdump path from $ZSH_COMPDUMP or $ZDOTDIR rather than assuming ~/.zcompdump, for the same portability reasons noted earlier.

🔧 Proposed fix
-    atload"[[ ! -s ~/.zcompdump.zwc || ~/.zcompdump -nt ~/.zcompdump.zwc ]] && zcompile ~/.zcompdump &!" \
+    atload'compdump="${ZSH_COMPDUMP:-${ZDOTDIR:-$HOME}/.zcompdump}"; [[ ! -s "${compdump}.zwc" || "$compdump" -nt "${compdump}.zwc" ]] && zcompile "$compdump" &!' \
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.zshrc around lines 75 - 77, The atload hook in the zinit line currently
hardcodes "~/.zcompdump"; change it to resolve the compdump path using
$ZSH_COMPDUMP if set, otherwise fall back to "$ZDOTDIR/.zcompdump" (or
"$HOME/.zcompdump" only if ZDOTDIR is unset) and use that resolved path in the
atload condition; update the zinit invocation (the line containing atload"[[ ...
]] && zcompile ~/.zcompdump &!") to reference the resolved variable instead of
the literal ~/.zcompdump so the hook is portable across different
ZDOTDIR/ZSH_COMPDUMP configurations.
🧹 Nitpick comments (2)
.zshrc (2)

18-18: zinit load adds unnecessary tracking overhead for binary/program plugins — prefer zinit light.

These plugins all use as"program" from"gh-r", meaning zinit only places a binary in $PATH — there's no shell code to track. Switching back to zinit light eliminates the per-plugin reporting overhead, which is directly at odds with this PR's sub-second startup goal.

♻️ Proposed change (apply to each `zinit load` line for binary plugins)
-zinit load sharkdp/bat
+zinit light sharkdp/bat

-zinit load eza-community/eza
+zinit light eza-community/eza

-zinit load sharkdp/fd
+zinit light sharkdp/fd

-zinit load junegunn/fzf
+zinit light junegunn/fzf

-zinit load BurntSushi/ripgrep
+zinit light BurntSushi/ripgrep

-zinit load tealdeer-rs/tealdeer
+zinit light tealdeer-rs/tealdeer

-zinit load ajeetdsoutu/zoxide
+zinit light ajeetdsoutu/zoxide

Note: starship/starship (line 18) uses its own atclone/src pattern for prompt init; whether it should use load or light depends on whether zinit report starship/starship is useful to you — the same logic applies.

Also applies to: 34-34, 40-40, 44-44, 51-51, 55-55, 59-59, 66-66

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.zshrc at line 18, Replace use of "zinit load" for plugins that only install
a binary (e.g., the "zinit load starship/starship" entry) with "zinit light" to
avoid unnecessary zinit tracking overhead; locate the zinit load lines
(including the specific "zinit load starship/starship" token and the other
reported occurrences) and change them to use "zinit light" for plugins that
provide only a program via as"program" or from"gh-r", leaving any entries that
actually require shell initialization (atclone/src) unchanged.

249-253: zcompile &! silently discards failures.

If zcompile fails (e.g., permission denied, disk full, syntax error in a newly edited .zshrc.local), the .zwc file is left stale or absent with no indication. The next shell start silently falls back to the uncompiled source, which is safe, but the failure goes unnoticed indefinitely.

♻️ Optional: surface failures without blocking startup
 auto_compile() {
     local file="$1"
     if [[ -f "$file" && ( ! -s "${file}.zwc" || "$file" -nt "${file}.zwc" ) ]]; then
-        zcompile "$file" &!
+        { zcompile "$file" || print -u2 "[zshrc] zcompile failed for $file" } &!
     fi
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.zshrc around lines 249 - 253, The auto_compile function currently fires
zcompile in the background with zcompile "$file" &!, which discards failures;
modify auto_compile to capture and report zcompile failures without blocking
startup by starting zcompile in background, saving its PID, waiting for it and
checking its exit status (or redirecting stderr to a log) and then emitting a
warning if it fails so stale or missing .zwc files are visible; reference the
auto_compile function, the zcompile invocation, and the generated .zwc files
when adding the wait+exit-status-check or stderr-to-log behavior so users get a
concise error message (or appended log entry) on permission/disk/syntax failures
instead of silent failure.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In @.zshrc:
- Around line 75-77: The atload hook in the zinit line currently hardcodes
"~/.zcompdump"; change it to resolve the compdump path using $ZSH_COMPDUMP if
set, otherwise fall back to "$ZDOTDIR/.zcompdump" (or "$HOME/.zcompdump" only if
ZDOTDIR is unset) and use that resolved path in the atload condition; update the
zinit invocation (the line containing atload"[[ ... ]] && zcompile ~/.zcompdump
&!") to reference the resolved variable instead of the literal ~/.zcompdump so
the hook is portable across different ZDOTDIR/ZSH_COMPDUMP configurations.

---

Nitpick comments:
In @.zshrc:
- Line 18: Replace use of "zinit load" for plugins that only install a binary
(e.g., the "zinit load starship/starship" entry) with "zinit light" to avoid
unnecessary zinit tracking overhead; locate the zinit load lines (including the
specific "zinit load starship/starship" token and the other reported
occurrences) and change them to use "zinit light" for plugins that provide only
a program via as"program" or from"gh-r", leaving any entries that actually
require shell initialization (atclone/src) unchanged.
- Around line 249-253: The auto_compile function currently fires zcompile in the
background with zcompile "$file" &!, which discards failures; modify
auto_compile to capture and report zcompile failures without blocking startup by
starting zcompile in background, saving its PID, waiting for it and checking its
exit status (or redirecting stderr to a log) and then emitting a warning if it
fails so stale or missing .zwc files are visible; reference the auto_compile
function, the zcompile invocation, and the generated .zwc files when adding the
wait+exit-status-check or stderr-to-log behavior so users get a concise error
message (or appended log entry) on permission/disk/syntax failures instead of
silent failure.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 840171f and d86fb4c.

📒 Files selected for processing (1)
  • .zshrc

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.zshrc (1)

199-236: ⚠️ Potential issue | 🟡 Minor

Respect ZDOTDIR in zshift-update paths.

The update routine still hardcodes $HOME/.zshrc, which will miss users who keep dotfiles under ZDOTDIR. Use the same ZDOTDIR-aware path here to stay consistent with the rest of the file.

🔧 Suggested fix
-    local DATE_STAMP BACKUP_FILE TEMP_ZSHRC UPDATE_URL
+    local DATE_STAMP BACKUP_FILE TEMP_ZSHRC UPDATE_URL ZSHRC_DIR
     DATE_STAMP=$(date +%Y%m%d_%H%M%S)
-    BACKUP_FILE="$HOME/.zshrc.zshift_${DATE_STAMP}.bak"
+    ZSHRC_DIR="${ZDOTDIR:-$HOME}"
+    BACKUP_FILE="$ZSHRC_DIR/.zshrc.zshift_${DATE_STAMP}.bak"
     TEMP_ZSHRC="$(mktemp)"
@@
-    if [ -f "$HOME/.zshrc" ]; then
+    if [ -f "$ZSHRC_DIR/.zshrc" ]; then
         echo -e "${YELLOW}:: Backing up current config to: ${NC}$BACKUP_FILE"
-        cp "$HOME/.zshrc" "$BACKUP_FILE"
+        cp "$ZSHRC_DIR/.zshrc" "$BACKUP_FILE"
     fi
@@
-    mv "$TEMP_ZSHRC" "$HOME/.zshrc"
+    mv "$TEMP_ZSHRC" "$ZSHRC_DIR/.zshrc"
@@
-                mv "$BACKUP_FILE" "$HOME/.zshrc"
+                mv "$BACKUP_FILE" "$ZSHRC_DIR/.zshrc"
             fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.zshrc around lines 199 - 236, The script still hardcodes $HOME/.zshrc;
define a ZDOTDIR-aware path (e.g. ZSHRC_PATH="${ZDOTDIR:-$HOME}/.zshrc") near
where DATE_STAMP/TEMP_ZSHRC are set and replace every occurrence of
"$HOME/.zshrc" and the BACKUP_FILE construction with ZSHRC_PATH (e.g.
BACKUP_FILE="${ZSHRC_PATH}.zshift_${DATE_STAMP}.bak"), and use ZSHRC_PATH for
the existence check, cp, mv and rollback restore so the update respects users
who set ZDOTDIR.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In @.zshrc:
- Around line 199-236: The script still hardcodes $HOME/.zshrc; define a
ZDOTDIR-aware path (e.g. ZSHRC_PATH="${ZDOTDIR:-$HOME}/.zshrc") near where
DATE_STAMP/TEMP_ZSHRC are set and replace every occurrence of "$HOME/.zshrc" and
the BACKUP_FILE construction with ZSHRC_PATH (e.g.
BACKUP_FILE="${ZSHRC_PATH}.zshift_${DATE_STAMP}.bak"), and use ZSHRC_PATH for
the existence check, cp, mv and rollback restore so the update respects users
who set ZDOTDIR.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d86fb4c and 3a7a238.

📒 Files selected for processing (1)
  • .zshrc

@0xdilshan 0xdilshan merged commit 0d3673c into main Feb 24, 2026
7 checks passed
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