mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-09 03:18:18 +00: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:
parent
339ed1d72e
commit
1850a985b5
1 changed files with 2 additions and 2 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue