Skip to content

perf(core): hot-path CPU reduction in agent loop#912

Merged
bug-ops merged 3 commits intomainfrom
feat/860-hotpath-cpu
Feb 25, 2026
Merged

perf(core): hot-path CPU reduction in agent loop#912
bug-ops merged 3 commits intomainfrom
feat/860-hotpath-cpu

Conversation

@bug-ops
Copy link
Owner

@bug-ops bug-ops commented Feb 25, 2026

Closes #860. Implements all four sub-issues: #880, #881, #882, #883.

Changes

Test plan

  • cargo +nightly fmt --check — passes
  • cargo clippy --workspace -- -D warnings — passes (0 warnings)
  • cargo nextest run --workspace --lib --bins — 2797 tests passed, 11 skipped

Replace should_compact() O(N) message scan with direct comparison
against cached_prompt_tokens (#880). Remove token_counter and
token_safety_margin from ContextManager as they are no longer needed.

Cache EnvironmentContext on Agent at bootstrap; on skill reload refresh
only git_branch and model_name instead of spawning a full git subprocess
every turn (#881).

Hash doom-loop content in-place by feeding stable segments directly into
DefaultHasher, eliminating the intermediate normalized String allocation
per tool iteration (#882).

Fix double count_tokens call in prune_stale_tool_outputs for ToolResult
parts: compute tokens once into a local and reuse (#883).
…mizations (#860)

Add 11 unit tests covering all four sub-issues:
- doom_loop_hash in-place correctness: 7 tests verifying hash output
  matches normalize_then_hash for plain text, tool_result, tool_use,
  mixed tags, multiple results, same-content different IDs, empty string
- refresh_git_branch: 2 tests verifying no panic and field isolation
- prune_stale_tool_outputs multi-part ToolResult pruned once per part

Update docs/src/architecture/performance.md and
docs/src/advanced/context.md to document cached EnvironmentContext,
O(1) compaction check, in-place doom-loop hashing, and single-call
token counting.

Update README.md and crates/zeph-core/README.md with optimized
agent loop hot-path notes.
@bug-ops bug-ops enabled auto-merge (squash) February 25, 2026 21:30
@bug-ops bug-ops merged commit 598c08a into main Feb 25, 2026
28 checks passed
@bug-ops bug-ops deleted the feat/860-hotpath-cpu branch February 25, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core documentation Improvements or additions to documentation performance Performance optimization rust size/L

Projects

None yet

1 participant