Skip to content

perf(api-server): normalize chat content linearly - #46079

Merged
teknium1 merged 1 commit into
mainfrom
hermes/api-server-normalize-linear
Jun 14, 2026
Merged

perf(api-server): normalize chat content linearly#46079
teknium1 merged 1 commit into
mainfrom
hermes/api-server-normalize-linear

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

API-server text content normalization now tracks accumulated length with a running counter instead of rescanning every collected part on each loop iteration.

Changes

  • gateway/platforms/api_server.py: replace repeated sum(len(part) for part in parts) with total_len updates for strings, text parts, and nested lists.
  • tests/gateway/test_api_server_normalize.py: add a regression test that monkeypatches the module-level sum name and proves normalization no longer calls it in the large-list path.

Validation

Check Result
RED test before implementation failed: sum_calls == 1000
Focused regression 1 passed in 0.15s
Microbench 1000 parts median 0.1481ms, min 0.1461ms
Targeted API server tests 175 passed in 3.9s
Syntax/diff checks py_compile + git diff --check passed

Notes

  • Output behavior is preserved: same newline joins, same text-part handling, same final truncation limit.
  • The untracked .plans/speed-optimization-audit.md remains intentionally excluded from this PR.

Infographic

Linear Chat Normalization

@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/api-server-normalize-linear 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: 10895 on HEAD, 10895 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5726 pre-existing issues carried over.

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

@teknium1
teknium1 merged commit 5105c36 into main Jun 14, 2026
28 checks passed
@teknium1
teknium1 deleted the hermes/api-server-normalize-linear branch June 14, 2026 10:25
AIalliAI pushed a commit to AIalliAI/Hermes that referenced this pull request Jun 14, 2026
T02200059 pushed a commit to T02200059/hermes-agent that referenced this pull request Jun 18, 2026
xyshanren pushed a commit to xyshanren/hermes-agent-cn that referenced this pull request Jun 25, 2026
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
Methodician added a commit to Methodician/hermes-agent that referenced this pull request Jul 4, 2026
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
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.

1 participant