open-webui/backend/open_webui
Classic298 54f06d8c53
perf: build chat responses without deep-copying the blob through model_dump (#27388)
Chat search built each result row with ChatTitleIdResponse(**chat.model_dump(), ...), which recursively copies the entire chat blob per row only for the constructor to ignore everything except id, title and timestamps: a 60-row search page deep-copied up to 60 full conversations. The folder listing, archived and export endpoints and every single-chat response did the same dump-and-revalidate dance via ChatResponse(**chat.model_dump()).

Search rows are now built from the five fields the response actually has (the snippet helper receives the blob by reference as before), and all 18 ChatResponse constructions use ChatResponse.model_validate(chat, from_attributes=True), which reads the fields off the already-validated ChatModel without copying the blob.

Benchmark (~500 KB chat blob):

| metric | before | after |
| --- | --- | --- |
| search result row | 0.05 ms | 0.003 ms |
| ChatResponse construction | 0.05 ms | 0.003 ms |
| per search page (60 rows) | 3 ms | 0.2 ms |

Beyond CPU, each converted row also stops materializing a second full copy of the conversation in memory while the page is being built.

Functionally verified: both construction styles produce identical model_dump() output for ChatResponse (including defaulted fields absent on ChatModel) and for search rows including the snippet.
2026-07-26 18:57:52 -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 refac 2026-07-24 01:54:36 -04:00
models refac 2026-07-26 18:46:39 -04:00
retrieval refac 2026-07-26 18:54:17 -04:00
routers perf: build chat responses without deep-copying the blob through model_dump (#27388) 2026-07-26 18:57:52 -04:00
socket fix: scope timer cancellation to the timer's owner (#27472) 2026-07-26 18:12:44 -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 fix: enforce automation limits in the builtin automation tools (#27523) 2026-07-26 17:55:56 -04:00
utils fix: refresh OAuth session before the id_token expires (#27520) 2026-07-26 18:56:18 -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 feat: add OpenSERP self-hosted web search backend (#27437) 2026-07-26 18:52:08 -04:00
constants.py refac 2026-06-29 05:46:51 -05:00
env.py refac 2026-07-26 18:36:49 -04:00
events.py Log upstream provider rejections at warn/error level (#27238) 2026-07-23 03:42:48 -04:00
functions.py refac 2026-07-23 03:39:56 -04:00
main.py refac 2026-07-26 18:46:39 -04:00
tasks.py refac 2026-07-16 21:57:43 -04:00