[PR #22280] [MERGED] perf: replace O(n²) unshift with O(n) push+reverse in buildMessages #97623

Closed
opened 2026-05-16 00:13:41 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/22280
Author: @Classic298
Created: 3/5/2026
Status: Merged
Merged: 3/6/2026
Merged by: @tjbck

Base: devHead: perf/build-messages-push-reverse


📝 Commits (1)

  • f2150e0 perf: replace O(n²) unshift with O(n) push+reverse in buildMessages

📊 Changes

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

View changed files

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

📄 Description

Array.unshift() is O(n) per call because it shifts all existing elements. In a loop building an n-element array, this makes the total cost O(n²). Replace with push() + reverse() which is O(n) total. Produces the identical message ordering.

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/22280 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 3/5/2026 **Status:** ✅ Merged **Merged:** 3/6/2026 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `perf/build-messages-push-reverse` --- ### 📝 Commits (1) - [`f2150e0`](https://github.com/open-webui/open-webui/commit/f2150e066f3bdf941aa45d36f141a56473fce292) perf: replace O(n²) unshift with O(n) push+reverse in buildMessages ### 📊 Changes **1 file changed** (+2 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/lib/components/chat/Messages.svelte` (+2 -2) </details> ### 📄 Description Array.unshift() is O(n) per call because it shifts all existing elements. In a loop building an n-element array, this makes the total cost O(n²). Replace with push() + reverse() which is O(n) total. Produces the identical message ordering. ### 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-05-16 00:13:41 -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#97623