Skip to content

perf: index history fallback updates - #381

Open
robinfai wants to merge 2 commits into
agentclientprotocol:mainfrom
robinfai:agent/indexed-history-merge
Open

perf: index history fallback updates#381
robinfai wants to merge 2 commits into
agentclientprotocol:mainfrom
robinfai:agent/indexed-history-merge

Conversation

@robinfai

@robinfai robinfai commented Aug 9, 2026

Copy link
Copy Markdown

Summary

  • pre-index fallback history updates by their existing identity and content keys
  • use lower-bound binary searches to find the first eligible fallback duplicate
  • preserve the existing merge order, deduplication keys, update count, and payload
  • cover earliest-match selection and advancing-cursor behavior with regression tests

Why

mergeHistoryUpdates previously ran findIndex over the remaining fallback
updates for every typed thread update. Large histories therefore repeatedly
serialized and scanned the same updates, with worst-case O(T * F) work.

The indexed implementation builds two O(F) lookup maps once and resolves each
match in O(log F). On a 77-turn, 2,306-item history with 5,112 fallback
updates and 3,566 typed updates, the isolated merge phase decreased from an
average 1,100.0 ms to 8.6 ms. An instrumented full-load comparison observed
adapter time decrease from 16.22 s to 15.05 s; the isolated merge measurement
is the stable performance claim because end-to-end timings include process and
transport variance.

This change does not trim ACP metadata, batch notifications, or introduce
client-specific behavior.

Validation

  • npm run typecheck
  • npm test — 357 passed, 28 skipped
  • npm run build

@robinfai
robinfai marked this pull request as ready for review August 9, 2026 16:07
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