Skip to content

perf: scope message equality check to content+parts instead of full object#842

Open
ved015 wants to merge 1 commit intosupermemoryai:mainfrom
ved015:perf/frontend
Open

perf: scope message equality check to content+parts instead of full object#842
ved015 wants to merge 1 commit intosupermemoryai:mainfrom
ved015:perf/frontend

Conversation

@ved015
Copy link
Copy Markdown
Contributor

@ved015 ved015 commented Apr 9, 2026

Summary

  • Replace JSON.stringify(entireMessage) with targeted field comparisons in areUIMessageArraysEqual
  • First compare content string directly (O(n) on string length, no allocation)
  • Fall back to JSON.stringify(parts) only skips metadata fields (createdAt, annotations, experimental_attachments) that never change during streaming

Why

areUIMessageArraysEqual is called on every message state update during chat streaming. Serializing the entire UIMessage object (including all metadata) on every comparison is expensive especially for messages with large tool invocations.

@MaheshtheDev please have a look

@graphite-app graphite-app bot requested a review from Dhravya April 9, 2026 14:58
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