open-webui/backend
Classic298 b2a9be27c5 perf: stop recopying the streamed message text on every delta
Every streamed token appended to the response text through a dict slot, which allocates a new string and copies everything received so far. A long answer pays that copy thousands of times on the event loop, so every other request on the worker waits behind it.

The appends now clear the slot before growing the string, which leaves a single reference and lets CPython resize it in place. This covers the six accumulation points in the Chat Completions streaming path. The Responses API transport copies its items before appending, so it holds two references and is unchanged.

Measured on CPython 3.12 with 10-character deltas:

| accumulated text | before | after |
|---|---|---|
| 100 KB | 5.97 ms | 0.98 ms |
| 250 KB | 29.53 ms | 2.83 ms |
| 1 MB | 659 ms | 15.5 ms |

Results match the replaced expressions for every input where the key exists and holds a string, key order and exception type included. Buffering into a list and joining at the end was the alternative, but each delta is read back immediately by the stream save, and joining per read measured 666 ms at 250 KB.
2026-08-23 22:37:08 +02:00
..
data refac: mv backend files to /open_webui dir 2024-09-04 16:54:48 +02:00
open_webui perf: stop recopying the streamed message text on every delta 2026-08-23 22:37:08 +02:00
.dockerignore fix: litellm config issue 2024-02-24 22:35:11 -08:00
.gitignore refac 2024-09-06 04:59:20 +02:00
dev.sh refac 2026-03-24 19:43:30 -05:00
requirements-min.txt perf: optional orjson JSON codec behind ENABLE_ORJSON (#27583) 2026-07-27 03:45:37 -04:00
requirements.txt chore: drop test-only dependencies from the Docker image and the published package (#28726) 2026-08-17 13:56:08 -07:00
start.sh refac 2026-06-17 03:01:11 +02:00
start_windows.bat fix: generate valid WEBUI_SECRET_KEY in start_windows.bat (#28061) 2026-08-10 23:22:43 -06:00