Skip to content

perf(cli): fast-path global version startup - #37704

Closed
yyzquwu wants to merge 1 commit into
NousResearch:mainfrom
yyzquwu:codex/perf-startup
Closed

perf(cli): fast-path global version startup#37704
yyzquwu wants to merge 1 commit into
NousResearch:mainfrom
yyzquwu:codex/perf-startup

Conversation

@yyzquwu

@yyzquwu yyzquwu commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Speeds up global hermes --version and hermes -V by answering them before the heavier CLI parser/config/logging imports run.

The fast path keeps normal startup semantics for cases that may need routing or profile setup: hermes version still uses the regular command path, Termux keeps its existing version behavior and disable flag, and host-side container/profile mode skips the fast path.

Related Issue

N/A - small CLI startup performance improvement found while comparing agent startup speed.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Security fix
  • Documentation update
  • Tests (adding or improving test coverage)
  • Refactor (no behavior change)
  • New skill (bundled or hub)

Changes Made

  • hermes_cli/main.py: adds an early global version fast path for exact --version / -V
  • hermes_cli/main.py: keeps project-root path precedence for direct source-checkout invocation
  • hermes_cli/main.py: skips the fast path when container mode or non-default active-profile routing may apply
  • tests/hermes_cli/test_tui_resume_flow.py: covers the fast path, direct script invocation, container/profile guards, preserved hermes version, and Termux disable scoping

How to Test

  1. Run the focused startup/version test file:
    python scripts/run_tests_parallel.py tests/hermes_cli/test_tui_resume_flow.py
  2. Run the focused startup/plugin regression file:
    python -m pytest tests/hermes_cli/test_startup_plugin_gating.py -q
  3. Run syntax/lint checks for the touched files:
    python -m py_compile hermes_cli/main.py tests/hermes_cli/test_tui_resume_flow.py
    python -m ruff check hermes_cli/main.py tests/hermes_cli/test_tui_resume_flow.py
    python scripts/check-windows-footguns.py --diff origin/main
  4. Smoke-test the version fast path from a source checkout:
    python -m hermes_cli.main --version
    python hermes_cli/main.py --version

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass (not run locally; focused tests below passed)
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Windows 11, plus focused pytest through WSL/Linux venv

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) - or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys - or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows - or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide - or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior - or N/A

For New Skills

N/A - this PR does not add a skill.

Screenshots / Logs

Focused startup/version test run:

python scripts/run_tests_parallel.py tests/hermes_cli/test_tui_resume_flow.py -> 52/52 passed in 62.7s

Focused startup/plugin regression run:

python -m pytest tests/hermes_cli/test_startup_plugin_gating.py -q -> 37 passed in 3.77s

Lint/compile/diff checks:

python -m py_compile hermes_cli/main.py tests/hermes_cli/test_tui_resume_flow.py -> passed
python -m ruff check hermes_cli/main.py tests/hermes_cli/test_tui_resume_flow.py -> All checks passed!
python scripts/check-windows-footguns.py --diff origin/main -> No Windows footguns found (2 files scanned)
git diff --check && git diff --cached --check -> clean

Local timing samples:

Baseline on main, WSL venv:
python -m hermes_cli.main --version -> avg 1750.9 ms, p50 1752.2 ms
python hermes_cli/main.py --version -> avg 1827.5 ms, p50 1772.7 ms

After this patch, WSL venv:
python -m hermes_cli.main --version -> avg 486.4 ms, p50 519.6 ms
python hermes_cli/main.py --version -> avg 555.3 ms, p50 560.8 ms

After this patch, Windows:
python -m hermes_cli.main --version -> avg 135.8 ms, p50 104.9 ms
python hermes_cli/main.py --version -> avg 198.7 ms, p50 199.5 ms

Local review:

codex review --disable plugins --disable memories --disable tool_search --disable apps --uncommitted -> No discrete correctness issues identified in the staged changes.

@alt-glitch alt-glitch added type/perf Performance improvement or optimization P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard labels Jun 2, 2026
@yyzquwu yyzquwu changed the title Fast-path global version startup perf(cli): fast-path global version startup Jun 2, 2026
@yyzquwu
yyzquwu marked this pull request as ready for review June 2, 2026 23:46

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the focused startup optimization. The non-Termux fast-path premise is still valid on current main, but this June patch needs target-aware salvage before it is safe.

Problems

  • Current hermes_cli/main.py:248 reads PROJECT_ROOT, but PROJECT_ROOT is initialized at hermes_cli/main.py:342, after the early exit. The changed early call at hermes_cli/main.py:320 in this PR would therefore need a current-main-safe version printer; the PR diff does not update that printer. Commit eb4040242 introduced the late PROJECT_ROOT reference after this PR was authored.
  • Current normal version output includes Install method at hermes_cli/main.py:4389-4395; the fast printer in this PR does not emit it, so the new exact-flag path would lose a current output field.

Suggested changes

  • Rework the pre-import helpers against current main so the printer derives its own root (or uses a dedicated stdlib-only helper) and preserves the current version-output fields.
  • Add direct-subprocess coverage for exact --version on both Termux and non-Termux paths after that rework.

Automated hermes-sweeper review.

Comment thread hermes_cli/main.py
elif _container_mode_may_be_active_fast():
return False

_print_fast_version_info()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When salvaging this early call onto current main, _print_fast_version_info() cannot use the target's PROJECT_ROOT: current main.py:248 reads it before its initialization at main.py:342. Please make the pre-import printer derive the root independently (and preserve current version output) before enabling this exit globally.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users labels Jul 13, 2026
@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Thanks @yyzquwu — this fast-path idea was a solid startup win. It has been salvaged into #62096, which moves the same logic into the canonical _startup_fast module with dedicated guard tests, so we're closing this one in favor of that implementation. Your original approach is credited in the salvage. Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants