Skip to content

Parallelize work done by the shell for the precmd hook.#12869

Draft
vorporeal wants to merge 2 commits into
masterfrom
david/parallelize-precmd-work
Draft

Parallelize work done by the shell for the precmd hook.#12869
vorporeal wants to merge 2 commits into
masterfrom
david/parallelize-precmd-work

Conversation

@vorporeal

@vorporeal vorporeal commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Description

precmd previously collected and JSON-escaped each prompt-context field serially, adding the latency of every independent operation before the next prompt could render.

Bash and Zsh now start the independent virtualenv, Conda, Node version, Git, and Zsh KUBECONFIG work concurrently through process substitutions, then drain their outputs into caller-local variables with a shared warp_read_parallel_outputs helper. This avoids temporary files and remains compatible with Bash 3.2.

Fish cannot run shell functions concurrently, so it uses a Fish-specific approach: an uncached Node version pipeline starts before the grouped Git lookup, then independent JSON-escaping pipelines run concurrently and write into a private per-shell directory that is removed on exit. Fish falls back to serial collection if that directory cannot be created.

Across all three shells, Git head and branch stay grouped to avoid duplicate Git commands, while the Node eligibility directory walk and cache updates remain in the parent shell so cache state persists across prompts. Benchmarking the directory walk inside the Node worker showed no measurable benefit, so it remains serial. The MSYS2-specific Bash path is unchanged.

Performance

Measured against the original serial prompt-context collection with all fields non-empty:

Shell Node cache Serial Parallel Speedup CPU overhead
Bash 3.2 Cold 62.4 ms 34.9 ms 1.79x (44% lower latency) +7%
Bash 3.2 Warm 32.1 ms 23.0 ms 1.39x (28% lower latency) +13%
Zsh 5.9 Cold 55.7 ms 29.7 ms 1.88x (47% lower latency) +12%
Zsh 5.9 Warm 29.1 ms 17.3 ms 1.68x (40% lower latency) +14%
Fish 4.2 Cold 34.9 ms 23.3 ms 1.50x (33% lower latency) +5%
Fish 4.2 Warm 11.2 ms 7.5 ms 1.48x (33% lower latency) +1%

A separate end-to-end Fish benchmark of the full precmd hook measured cold latency improving from 58.5 ms to 47.1 ms (1.24x / 19.5% lower, +4.6% CPU) and warm latency improving from 35.3 ms to 31.7 ms (1.11x / 10.2% lower, +1.0% CPU).

The collection benchmark ran from a package-containing checkout with a real .git directory, using Node v22.13.1 and Hyperfine. Each result is the per-hook mean from batches of 20 collections, with 5 warmups and 25–30 measured runs. The Fish full-hook benchmark used batches of 30 collections, with 3 warmups and 20 measured runs. CPU overhead is combined user and system time relative to the serial baseline.

Linked Issue

N/A

Testing

  • /bin/bash -n app/assets/bundled/bootstrap/bash_body.sh
  • /bin/zsh -n app/assets/bundled/bootstrap/zsh_body.sh
  • fish -n app/assets/bundled/bootstrap/fish.sh
  • Parsed generated/minified Bash, Zsh, and Fish bootstrap forms.
  • Verified caller-local output assignment on Bash 3.2 and Zsh 5.9, including Git-value splitting with Zsh KSH_ARRAYS enabled.
  • Verified byte-identical serial/parallel Fish precmd payloads for named and detached Git HEADs with cold and warm Node caches.
  • Verified Fish's serial fallback and shared JSON escaping behavior.
  • Ran the Hyperfine benchmarks documented above.

No new automated tests were added because this is performance-sensitive shell bootstrap behavior validated directly in all three target shells and through comparative benchmarks.

  • I have manually tested my changes locally with ./script/run

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

CHANGELOG-NONE

Co-Authored-By: Oz oz-agent@warp.dev

@cla-bot cla-bot Bot added the cla-signed label Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@vorporeal vorporeal force-pushed the david/parallelize-precmd-work branch from 86f5f12 to 7529a91 Compare June 21, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant