Skip to content

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

Merged
MaheshtheDev merged 1 commit intosupermemoryai:mainfrom
ved015:perf/frontend
Apr 12, 2026
Merged

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

Conversation

@ved015
Copy link
Copy Markdown
Member

@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
Copy link
Copy Markdown
Member

@MaheshtheDev MaheshtheDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MaheshtheDev MaheshtheDev merged commit cfd587e into supermemoryai:main Apr 12, 2026
4 of 5 checks passed
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