[PR #21884] [MERGED] perf: fast-path comparison in ResponseMessage to skip JSON.stringify during streaming #41951

Closed
opened 2026-04-25 14:01:49 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/21884
Author: @Classic298
Created: 2/25/2026
Status: Merged
Merged: 2/26/2026
Merged by: @tjbck

Base: devHead: perf/response-message-fast-compare


📝 Commits (1)

  • 28effdf perf: fast-path comparison in ResponseMessage to skip JSON.stringify during streaming

📊 Changes

1 file changed (+10 additions, -2 deletions)

View changed files

📝 src/lib/components/chat/Messages/ResponseMessage.svelte (+10 -2)

📄 Description

ResponseMessage compared the entire message object via JSON.stringify on every reactive tick to detect changes. During streaming, content changes on every token, making the two O(content_length) JSON.stringify calls always return different results — pure wasted work. Add a fast O(1) comparison on content and done fields first. When either differs (the common streaming case), skip straight to cloning. Only fall through to the expensive JSON.stringify comparison for infrequent changes like sources, annotations, or status updates.

this is a completely invisible change - free lunch

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/21884 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 2/25/2026 **Status:** ✅ Merged **Merged:** 2/26/2026 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `perf/response-message-fast-compare` --- ### 📝 Commits (1) - [`28effdf`](https://github.com/open-webui/open-webui/commit/28effdf5b3b1d2ef1befe58ddab171d657275d75) perf: fast-path comparison in ResponseMessage to skip JSON.stringify during streaming ### 📊 Changes **1 file changed** (+10 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/lib/components/chat/Messages/ResponseMessage.svelte` (+10 -2) </details> ### 📄 Description ResponseMessage compared the entire message object via JSON.stringify on every reactive tick to detect changes. During streaming, content changes on every token, making the two O(content_length) JSON.stringify calls always return different results — pure wasted work. Add a fast O(1) comparison on content and done fields first. When either differs (the common streaming case), skip straight to cloning. Only fall through to the expensive JSON.stringify comparison for infrequent changes like sources, annotations, or status updates. <ins>**this is a completely invisible change - free lunch**</ins> ### Contributor License Agreement <!-- 🚨 DO NOT DELETE THE TEXT BELOW 🚨 Keep the "Contributor License Agreement" confirmation text intact. Deleting it will trigger the CLA-Bot to INVALIDATE your PR. --> By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 14:01:49 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#41951