mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2026-03-18 11:24:39 +01:00
UI: Optimize chat streaming by batching morphdom to one update per animation frame
The monitor physically cannot paint faster than its refresh rate, so intermediate morphdom calls between frames do redundant parsing, diffing, and patching work that is never displayed.
This commit is contained in:
parent
5ddc1002d2
commit
a4bef860b6
|
|
@ -269,7 +269,21 @@ function removeLastClick() {
|
|||
document.getElementById("Remove-last").click();
|
||||
}
|
||||
|
||||
let pendingMorphdomData = null;
|
||||
let morphdomRafId = null;
|
||||
|
||||
function handleMorphdomUpdate(data) {
|
||||
pendingMorphdomData = data;
|
||||
if (!morphdomRafId) {
|
||||
morphdomRafId = requestAnimationFrame(() => {
|
||||
morphdomRafId = null;
|
||||
applyMorphdomUpdate(pendingMorphdomData);
|
||||
pendingMorphdomData = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function applyMorphdomUpdate(data) {
|
||||
// Determine target element and use it as query scope
|
||||
var target_element, target_html;
|
||||
if (data.last_message_only) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue