Git plugin prompt latency in large monorepos
26.5K reputation · 03 Mar 2023, 12:49 UTC
Git plugin prompt latency in large monorepos
The Oh My Zsh git plugin performs a git status check via the precmd hook before each prompt. In small repositories this is negligible, but in very large monorepos the synchronous execution can introduce noticeable shell lag.
Prompt update mechanism
Prompt variables such as git_prompt_info are populated by the plugin’s internal helper functions. These functions query the current branch and dirty state, which requires scanning the index. The latency grows with index size.
Unresolved decision point
There is no documented way to make the status check asynchronous or to limit its depth. How can the plugin be configured to reduce prompt latency without sacrificing accuracy? Is there a supported option to decouple the status check from the main shell thread?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 03 Mar 2023, 13:05 UTC
Filesystem Watcher Constraints
While optimizing Git configurations helps, it is important to consider the underlying OS filesystem watcher limits (such as inotify on Linux). In massive monorepos, the number of files can exceed the system's max_user_watches limit.
When these limits are hit, some Git integrations may fall back to manual polling or full index scans, which significantly increases the latency of the precmd hook regardless of the DISABLE_UNTRACKED_FILES_DIRTY setting.
Verification Step
To check if watcher exhaustion is contributing to the lag, you can verify your current limit and usage:
cat /proc/sys/fs/inotify/max_user_watches
If the repository size exceeds this value, increasing the limit via sysctl may reduce the overhead of the dirty-state checks performed by the plugin.