open-webui/backend/open_webui
Classic298 d29685275b
perf: drop the full-payload deepcopy in the OpenAI to Ollama conversion (#27371)
convert_payload_openai_to_ollama deep-copied the entire request payload on every completion routed to an Ollama model, and again on every tool-call iteration. The cost of that copy scales with the number of messages and nested content parts in the history, so long chats pay the most, purely as CPU work before the request even leaves the server.

The function only ever mutates two things: it deletes keys on the top-level dict and on the nested options dict. convert_messages_openai_to_ollama already builds fresh message dicts. Shallow-copying exactly those two levels therefore preserves behavior while removing the whole-tree copy.

Benchmark (per conversion call):

| payload | before | after | speedup |
| --- | --- | --- | --- |
| 200-message text chat (~180 KB) | 0.22 ms | 0.057 ms | 4x |
| 20-message chat + 1 MB base64 image | 0.41 ms | 0.38 ms | 1.1x |

The image row barely moves because deepcopy shares immutable strings; the win comes from container-heavy histories, which are exactly the payloads that grow over a conversation's lifetime.

The output is byte-identical to the previous implementation (verified against it, including dict key order, root parameter hoisting, max_tokens remapping, stop handling and response_format precedence), and the caller's payload is left unmodified exactly as before.
2026-07-27 01:47:23 -04:00
..
data refac: mv backend files to /open_webui dir 2024-09-04 16:54:48 +02:00
internal perf: cut per-request database session overhead (#27385) 2026-07-23 17:49:48 -05:00
migrations chore: format 2026-07-27 00:12:47 -04:00
models chore: format 2026-07-27 00:12:47 -04:00
retrieval refac 2026-07-27 01:21:32 -04:00
routers fix: restrict folder deletion to the owner or an admin (#27003) 2026-07-27 01:46:58 -04:00
socket refac 2026-07-26 23:49:03 -04:00
static refac 2026-07-20 22:27:13 -04:00
storage refac: modernize type annotations (PEP 604 / PEP 585) 2026-05-12 17:10:15 +09:00
tools refac 2026-07-27 00:27:38 -04:00
utils perf: drop the full-payload deepcopy in the OpenAI to Ollama conversion (#27371) 2026-07-27 01:47:23 -04:00
__init__.py refac 2026-06-17 03:01:11 +02:00
alembic.ini fix: Alembic CLI commands from failing 2025-08-15 04:17:47 -04:00
config.py chore: format 2026-07-27 00:12:47 -04:00
constants.py refac 2026-06-29 05:46:51 -05:00
env.py refac 2026-07-27 01:21:32 -04:00
events.py refac 2026-07-26 19:10:41 -04:00
functions.py refac 2026-07-23 03:39:56 -04:00
main.py refac 2026-07-27 01:46:10 -04:00
tasks.py refac 2026-07-26 22:45:11 -04:00