mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-25 01:36:29 -05:00
[PR #22280] [MERGED] perf: replace O(n²) unshift with O(n) push+reverse in buildMessages #130242
Reference in New Issue
Block a user
📋 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:
dev← Head:perf/build-messages-push-reverse📝 Commits (1)
f2150e0perf: 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.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.