Files
open-webui/backend/open_webui/utils
Classic298andGitHub b0fdc00452 perf: write task payloads to Redis as bytes (#28833)
Saving a streaming response serialized the payload with orjson, decoded it to
str, scanned it for the three Unicode line separators and let redis-py encode
it straight back to UTF-8: on an 8 MB non-ASCII chat that is 6.9 ms and ~22 MB
of transient buffers per write, synchronously on the event loop.

json_codec now exposes dumps_bytes, which returns the serialized payload as
UTF-8 bytes without the line-separator escaping, and the two Redis writes in
tasks.py use it. That escaping only protects line-framed protocols such as
SSE; every reader of these Redis values re-parses them before anything is
served, and the escaped and raw forms parse identically, so mixed versions
during a rolling deploy interoperate both ways. The same write drops to
0.9 ms and one 8 MB buffer (7.5x), with 31-66% saved on KB-sized writes.
With ENABLE_ORJSON off, dumps_bytes wraps stdlib json, behaviour unchanged.

The str path keeps the escaping but applies it with chained str.replace
instead of a translate table, cutting a separator-containing 8 MB payload
from 312 ms to 5.7 ms with byte-identical output.
2026-08-20 12:58:52 -07:00
..
2026-07-31 17:41:14 -04:00
2026-08-13 21:02:17 -06:00
2026-08-13 16:42:10 -06:00
2026-07-31 17:30:47 -04:00
2026-07-31 17:41:14 -04:00
2026-07-31 17:41:14 -04:00
2026-08-17 00:57:57 -07:00
2026-08-10 19:28:21 -06:00
2026-08-13 00:07:31 -06:00
2026-08-16 22:56:19 -07:00
2026-08-17 00:57:57 -07:00
2026-08-10 20:13:03 -06:00
2026-08-19 22:48:32 -07:00
2026-08-16 22:52:24 -07:00
2026-07-31 17:41:14 -04:00