mirror of
https://github.com/open-webui/open-webui.git
synced 2026-03-11 17:47:44 -05:00
perf: replace O(n²) unshift with O(n) push+reverse in buildMessages (#22280)
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.
This commit is contained in:
@@ -90,11 +90,11 @@
|
||||
}
|
||||
visitedMessageIds.add(message.id);
|
||||
|
||||
_messages.unshift(message);
|
||||
_messages.push(message);
|
||||
message = message.parentId !== null ? history.messages[message.parentId] : null;
|
||||
}
|
||||
|
||||
messages = _messages;
|
||||
messages = _messages.reverse();
|
||||
};
|
||||
|
||||
// Throttle message list rebuilds to once per animation frame during streaming.
|
||||
|
||||
Reference in New Issue
Block a user