Skip to content

perf(ui): convert message pairing to O(n) forward pass in chain-of-thought#846

Open
ishaanxgupta wants to merge 1 commit intosupermemoryai:mainfrom
ishaanxgupta:ishaan/chain
Open

perf(ui): convert message pairing to O(n) forward pass in chain-of-thought#846
ishaanxgupta wants to merge 1 commit intosupermemoryai:mainfrom
ishaanxgupta:ishaan/chain

Conversation

@ishaanxgupta
Copy link
Copy Markdown
Contributor

Summary

Optimizes the message pairing algorithm in the ChainOfThought component.

Previously, for every user message in the chat thread, the component created a new sliced array and iterated forward with .find() to locate the next assistant message. This resulted in an $O(n^2)$ time complexity and repeated garbage collection, which becomes noticeably sluggish on long conversations.

Changes

  • Removed the .slice(i + 1).find(...) nested iteration inside the for loop.
  • Introduced a lastUserPair state tracker to map the first subsequent assistant message directly to the most recent user message in a single $O(n)$ forward pass.

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