Repository navigation
⚡ Bolt: Optimize file staleness checks with native Zsh globbing - #495
Conversation
Replaced external `stat` and `date` subprocess calls with native Zsh extended globbing `(#qN.ms+max_age)` to calculate file age. This eliminates costly fork/exec overhead during shell startup and simplifies the logic for checking expired command caches and happy CLI updates. Also wraps the local options modification in `.zshrc` inside an anonymous function to avoid leaking `extended_glob` to the rest of the shell. Co-authored-by: kaovilai <11228024+kaovilai@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughStamp-file expiration checks in ChangesZsh cache expiration
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Code Review
This pull request replaces subprocess-based file age checks (using stat and date) with native Zsh extended globbing ((#qN.ms+seconds)) in .zshrc and zsh/command-cache.zsh to optimize shell startup performance. It also adds a learning note documenting this optimization. Feedback suggests simplifying the logic in .zshrc by initializing the expired variable to 1 and writing the array check more concisely.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| local expired=0 | ||
| if [[ -f "$stamp" ]]; then | ||
| local mtime now | ||
| mtime=$(stat -f "%m" "$stamp" 2>/dev/null || stat -c "%Y" "$stamp" 2>/dev/null) || expired=0 | ||
| now=$(date +%s) | ||
| (( now - mtime > 86400 )) && expired=0 || expired=1 | ||
| () { | ||
| setopt local_options extended_glob | ||
| local -a expired_files | ||
| expired_files=("$stamp"(#qN.ms+86400)) | ||
| if (( ${#expired_files} > 0 )); then | ||
| expired=1 | ||
| fi | ||
| } | ||
| else | ||
| expired=0 | ||
| expired=1 | ||
| fi |
There was a problem hiding this comment.
We can simplify this logic and eliminate the else block by initializing expired=1 (expired by default). This also allows us to write the array initialization and the condition much more concisely and idiomatically in Zsh.
local expired=1
if [[ -f "$stamp" ]]; then
() {
setopt local_options extended_glob
local -a expired_files=( "$stamp"(#qN.ms+86400) )
(( $#expired_files )) || expired=0
}
fi
Code ReviewThe glob qualifier approach is correct and the logic inversion (fixing the confusing Two issues worth addressing: 1.
|
There was a problem hiding this comment.
Pull request overview
This PR optimizes cache/staleness checks in the dotfiles’ Zsh startup logic by replacing external stat/date subprocess usage with native Zsh extended glob qualifiers ((#qN.ms+seconds)), reducing fork/exec overhead during shell initialization.
Changes:
- Updated
cache-file-expiredto use extended glob qualifiers for age checks instead of computing epoch timestamps via subprocesses. - Updated the
.zshrc“happy” update stamp TTL check to use the same native glob-qualifier approach. - Added a short Bolt learning note documenting the optimization pattern.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
zsh/command-cache.zsh |
Replaces stat/date-based expiry logic with Zsh native glob qualifiers in cache-file-expired. |
.zshrc |
Replaces stat/date-based “happy-update-check” stamp staleness logic with Zsh native glob qualifiers. |
.jules/bolt.md |
Documents the learning/action for using Zsh extended globbing to avoid subprocess overhead. |
Comments suppressed due to low confidence (1)
zsh/command-cache.zsh:35
- This allocates an array and counts elements just to test whether the glob matched. You can avoid the array entirely and do a direct non-empty check on the qualified path, which is simpler and avoids extra allocations in this hot path.
local -a expired_files
expired_files=("$file"(#qN.ms+${max_age}))
if (( ${#expired_files} > 0 )); then
return 0 # Cache expired
else
return 1 # Cache still valid
fi
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| local -a expired_files | ||
| expired_files=("$stamp"(#qN.ms+86400)) | ||
| if (( ${#expired_files} > 0 )); then | ||
| expired=1 | ||
| fi |
|
@jules this branch now has merge conflicts with Note Responses generated with Claude |
I have successfully fetched the latest main branch and resolved the merge conflicts in |
Replaced external `stat` and `date` subprocess calls with native Zsh extended globbing `(#qN.ms+max_age)` to calculate file age. This eliminates costly fork/exec overhead during shell startup and simplifies the logic for checking expired command caches and happy CLI updates. Also wraps the local options modification in `.zshrc` inside an anonymous function to avoid leaking `extended_glob` to the rest of the shell. Co-authored-by: kaovilai <11228024+kaovilai@users.noreply.github.com>
Signed-off-by: Tiger Kaovilai <passawit.kaovilai@gmail.com> # Conflicts: # .jules/bolt.md
* ⚡ Bolt: Optimize file staleness checks with native Zsh globbing Replaced external `stat` and `date` subprocess calls with native Zsh extended globbing `(#qN.ms+max_age)` to calculate file age. This eliminates costly fork/exec overhead during shell startup and simplifies the logic for checking expired command caches and happy CLI updates. Also wraps the local options modification in `.zshrc` inside an anonymous function to avoid leaking `extended_glob` to the rest of the shell. Co-authored-by: kaovilai <11228024+kaovilai@users.noreply.github.com> * ⚡ Bolt: Optimize file staleness checks with native Zsh globbing Replaced external `stat` and `date` subprocess calls with native Zsh extended globbing `(#qN.ms+max_age)` to calculate file age. This eliminates costly fork/exec overhead during shell startup and simplifies the logic for checking expired command caches and happy CLI updates. Also wraps the local options modification in `.zshrc` inside an anonymous function to avoid leaking `extended_glob` to the rest of the shell. Co-authored-by: kaovilai <11228024+kaovilai@users.noreply.github.com> --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: kaovilai <11228024+kaovilai@users.noreply.github.com>
💡 What: Replaced external
statanddatesubprocess calls with native Zsh extended globbing(#qN.ms+max_age)to calculate file staleness.🎯 Why: Spawning subprocesses like
statanddateis a significant bottleneck in shell scripts. By using Zsh native built-ins and glob qualifiers, we achieve the same functionality much faster and improve shell initialization.📊 Impact: Eliminates expensive fork/exec overheads when checking if cache files are expired during shell startup and initialization, reducing startup latency.
🔬 Measurement: Verify cache expiration by manually editing a file's modification time (e.g.
touch -d '2 days ago' ~/.zsh-command-cache/happy-update-check) and verifying that cache generation is triggered or cache functions report the correct TTL.PR created automatically by Jules for task 6081486736791090423 started by @kaovilai
Summary by CodeRabbit