Skip to content

perf: fast path for zsh rprompt - 55ms to 5ms (8x faster)#2692

Open
AasheeshLikePanner wants to merge 8 commits intoantinomyhq:mainfrom
AasheeshLikePanner:fix/2574-zsh-rprompt-perf
Open

perf: fast path for zsh rprompt - 55ms to 5ms (8x faster)#2692
AasheeshLikePanner wants to merge 8 commits intoantinomyhq:mainfrom
AasheeshLikePanner:fix/2574-zsh-rprompt-perf

Conversation

@AasheeshLikePanner
Copy link
Copy Markdown

Summary

This PR fixes the flaky zsh rprompt benchmark in #2574 by implementing an early-exit fast path for the zsh rprompt command when no conversation ID is present.

Changes

Added a fast path in main.rs that checks for zsh rprompt command BEFORE any heavy initialization:

  • If _FORGE_CONVERSATION_ID is NOT set → print static prompt and exit immediately
  • If _FORGE_CONVERSATION_ID IS set → continue with normal full initialization
    This bypasses:
  • ForgeInfra (HTTP client, gRPC, MCP, .env loading)
  • ForgeRepo (SQLite connection pool)
  • ForgeServices (20+ services)

Results

Benchmark Before After Improvement
CI (ubuntu-latest) 55ms 5ms 8x faster
Local 33ms 7ms 4.7x faster

Benchmark (CI)

avg: 5ms
p75: 6ms
threshold: 80ms
Status: PASS

Before Screenshot

image

After Screenshot

image

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 25, 2026

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Bypasses heavy initialization (ForgeInfra, ForgeRepo, ForgeServices)
when _FORGE_CONVERSATION_ID is not set.
@AasheeshLikePanner AasheeshLikePanner force-pushed the fix/2574-zsh-rprompt-perf branch from d9f1666 to 7dd2327 Compare March 25, 2026 13:16
- Check exact argument positions to avoid false positives
- Check BEFORE Cli::parse() to avoid parsing overhead
- Falls back to normal path when _FORGE_CONVERSATION_ID is set
@AasheeshLikePanner AasheeshLikePanner force-pushed the fix/2574-zsh-rprompt-perf branch 2 times, most recently from e6252a5 to 47c6104 Compare March 26, 2026 04:51
- Add direct SQLite query via rusqlite to fetch rprompt data
- Bypass full Forge infrastructure stack for ~7ms performance
- Uses json_extract to pull usage.{total_tokens,cost,model} from context
- Falls back to normal path if DB/table doesn't exist
- Fix edge case: single quote string in model extraction

Co-Authored-By: ForgeCode <noreply@forgecode.dev>
@AasheeshLikePanner AasheeshLikePanner force-pushed the fix/2574-zsh-rprompt-perf branch from 47c6104 to b8c50c3 Compare March 26, 2026 11:59
Conflicts resolved:
- Cargo.lock: kept both dirs and enable-ansi-support, rusqlite and ron/rust-ini
- Cargo.toml: merged dependencies

perf: second fast path for zsh rprompt with conversation ID

Co-Authored-By: ForgeCode <noreply@forgecode.dev>
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.

3 participants