Skip to content

perf(termux): speed up non-tui cli startup (salvage #29438)#30121

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-c6a63691
May 22, 2026
Merged

perf(termux): speed up non-tui cli startup (salvage #29438)#30121
teknium1 merged 2 commits into
mainfrom
hermes/hermes-c6a63691

Conversation

@teknium1

@teknium1 teknium1 commented May 22, 2026

Copy link
Copy Markdown
Contributor

Salvage of #29438 — Termux non-TUI cold-start optimizations from @adybag14-cyber, cherry-picked onto current main (was 58 commits behind) with an additional fix on top.

What this PR makes true

On Termux/Android, hermes, hermes chat, hermes -z ..., and hermes version skip the full subparser tree and use the lightweight top-level parser. Background update prefetch and full bundled-skill rehash are opt-in (off by default) on Termux. Non-Termux behavior is unchanged.

Author-reported timings (Termux):

Command Before After
--version / version 0.36s 0.22s
chat (invalid args) 0.30s 0.22s
sync_skills(quiet=True) 0.075s 0.0001s cached
--help (full parser) ~0.32s unchanged

Commits

  1. perf(termux): speed up non-tui cli startup@adybag14-cyber's original commit (cherry-picked, authorship preserved):

    • _try_termux_fast_cli_launch() parallel to the already-merged _try_termux_fast_tui_launch() (perf(termux): speed up tui cold start #29419).
    • _prepare_agent_startup() extracted from cmd_acp (pure refactor, both call sites updated).
    • Bundled-skill sync stamp keyed by checkout revision (.termux_bundled_sync_stamp under get_hermes_home()/skills/).
    • Three escape hatches: HERMES_TERMUX_DISABLE_FAST_CLI=1, HERMES_TERMUX_PREFETCH_UPDATES=1, HERMES_TERMUX_FORCE_SKILLS_SYNC=1.
  2. fix(termux): resolve packed-refs and worktree refs in skill-sync fingerprint — follow-up on top:

    • Original _read_git_revision_fingerprint() only checked loose refs in the worktree gitdir. Two real cases hit the unresolved branch and produced a constant-string fingerprint (skill sync would never re-run):
      • Repos after git gc where active refs live in packed-refs.
      • Linked worktrees, whose branch ref lives in <commondir>/refs/heads/ (reproduced on the worktree this salvage was built in — fingerprint was refs/heads/<branch>:unresolved before, refs/heads/<branch>:<sha> after).
    • Now: parse commondir, check both gitdir and common dir for loose refs, parse packed-refs, and label genuinely-unresolvable refs explicitly (:unresolved — still stable, and __version__ invalidates after hermes update).

Validation

Result
Cherry-pick onto current main Clean (no conflicts)
tests/hermes_cli/test_tui_resume_flow.py 38 passed (34 from #29438 + 4 new)
tests/hermes_cli/test_startup_plugin_gating.py + test_subparser_routing_fallback.py + test_ignore_user_config_flags.py 48 passed
E2E: _read_git_revision_fingerprint() against this worktree git:refs/heads/<branch>:<sha> (was :unresolved before fix)
E2E: same call against the main checkout git:refs/heads/main:<sha>
tests/hermes_cli/test_tui_npm_install.py::test_make_tui_argv_skips_build_only_on_termux_when_fresh pre-existing failure on origin/main (--expose-gc argv assertion), unrelated

Closes #29438.

Infographic

termux-cold-start-non-tui

adybag14-cyber and others added 2 commits May 21, 2026 14:23
…erprint

The bundled-skill sync stamp added in the cherry-picked salvage commit
parsed .git/HEAD and looked for a loose ref file in the worktree gitdir
only, so two real cases hit the unresolved branch:

- repos after `git gc` where active refs live in packed-refs
- linked worktrees, whose branch ref lives in <commondir>/refs/heads/
  (verified on the worktree this salvage was built in)

Both fell back to a constant-string fingerprint, so post-commit launches
would never re-run the real skill sync. Now we resolve packed-refs and
check both the worktree gitdir and the common dir for loose refs.

Adds three tests covering: packed-refs resolution, worktree common-dir
packed lookup, worktree common-dir loose lookup, and the explicit
'unresolved' marker (still stable + version-fallback-safe).
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-c6a63691 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9004 on HEAD, 9004 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4758 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@teknium1 teknium1 merged commit 2a474bc into main May 22, 2026
17 of 18 checks passed
@teknium1 teknium1 deleted the hermes/hermes-c6a63691 branch May 22, 2026 00:19
@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 May 22, 2026
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 type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants