perf(core): optimize agent hot path across 9 subsystems#669
Merged
Conversation
This was
linked to
issues
Feb 19, 2026
- Enable SQLite WAL mode with SYNCHRONOUS=NORMAL (#639) - Replace O(n*iterations) token scan with cached_prompt_tokens (#640) - Defer maybe_redact to stream completion boundary (#641) - Replace format_tool_output allocation with Write-into-buffer (#642) - Change ToolCall.params from HashMap to serde_json::Map (#643) - Pre-join static system prompt sections into LazyLock (#644) - Replace doom-loop string storage with content hash (#645) - Return &'static str from detect_image_mime (#646) - Replace block_on in history persist with async spawn (#647)
7552418 to
753c1a8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #621 — optimize the core agent loop by eliminating unnecessary allocations, O(n) scans, and blocking operations across 9 targeted subsystems.
cached_prompt_tokens(Replace O(n*iterations) token scan with incremental counter #640)maybe_redactto stream completion boundary (Defer maybe_redact to flush_chunks() boundary #641)format_tool_outputallocation withWrite-into-buffer (Replace format_tool_output allocation with Write-into-buffer #642)ToolCall.paramsfromHashMaptoserde_json::Map(Use serde_json::Map directly for tool call params #643)LazyLock<String>(Pre-join static system prompt sections into LazyLock #644)&'static strfromdetect_image_mimewith case-insensitive matching (Return &'static str from detect_image_mime #646)block_onin history persist with fire-and-forget async spawn (Replace block_on in history persist with spawn_blocking #647)10 files changed, +198 -84, 6 new tests (2017 total passing).
Test plan
cargo +nightly fmt --checkpassescargo clippy --workspace -- -D warningspasses (0 warnings)cargo nextest run --workspace --lib --bins— 2017 passed, 9 skippedVec<u64>path