Skip to content

perf(desktop): replace messages.map with backwards-walk index in streaming handlers#2055

Merged
esengine merged 1 commit into
esengine:mainfrom
CVEngineer66:pr-f8b33031
May 27, 2026
Merged

perf(desktop): replace messages.map with backwards-walk index in streaming handlers#2055
esengine merged 1 commit into
esengine:mainfrom
CVEngineer66:pr-f8b33031

Conversation

@CVEngineer66

@CVEngineer66 CVEngineer66 commented May 27, 2026

Copy link
Copy Markdown
Contributor

Before

Every streaming event (model.delta, model.final, tool.preparing, tool.intent, tool.result) called state.messages.map(m => condition ? updated : m) — iterating ALL messages and creating a full new array on every chunk. 500 messages × 5000 chunks = 2.5M element operations per session.

After

Backwards walk from the end (streaming always targets the latest assistant turn) replaces only the target message. [...state.messages.slice(0, i), updated, ...state.messages.slice(i + 1)] — O(target) not O(all). Spread creates a new array reference without iterating or transforming every element.

@esengine esengine merged commit 7f67bc2 into esengine:main May 27, 2026
4 checks passed
@CVEngineer66 CVEngineer66 deleted the pr-f8b33031 branch May 31, 2026 15:34
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.

2 participants