Skip to content

fix: Optimize thought completion marking from O(n²) to O(n)#1486

Draft
charlesvien wants to merge 1 commit intomainfrom
04-03-optimize_thought_completion_marking_from_o_n_to_o_n_
Draft

fix: Optimize thought completion marking from O(n²) to O(n)#1486
charlesvien wants to merge 1 commit intomainfrom
04-03-optimize_thought_completion_marking_from_o_n_to_o_n_

Conversation

@charlesvien
Copy link
Copy Markdown
Member

@charlesvien charlesvien commented Apr 3, 2026

Problem

markThoughtCompletion scanned all subsequent items for every thought item using .slice().some(), making it O(n²) in conversation length.

Changes

  1. Replace nested scan with a single reverse pass using a Set to track seen turn contexts
  2. Reduce time complexity from O(n²) to O(n) by eliminating repeated .slice().some() calls
  3. Preserve identical completion semantics (checks for subsequent session_update or turnComplete)

How did you test this?

Manually

@charlesvien charlesvien changed the title Optimize thought completion marking from O(n²) to O(n) fix: Optimize thought completion marking from O(n²) to O(n) Apr 3, 2026
Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

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