From f98ca224c5d84cdcbcaf9bcbfdd1bf438f16d625 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Wed, 30 Sep 2026 17:42:53 +0200 Subject: [PATCH] perf: use the faster JSON encoder by default (#31616) ENABLE_ORJSON has shipped as an option since v0.11.0 (2026-07-27), five releases and two months ago, and orjson is already installed with every instance. The only two problems ever found with it (rare line break characters splitting a stream, and extra encoding options being ignored) were fixed in v0.11.1 and nothing has come up since. The regression suite at https://github.com/open-webui/tests now runs 222 tests with the option on and off side by side, on SQLite, Postgres, several workers sharing one Redis with some on and some off, and in the browser: chats, completions for every provider format, tool calls, citations, all workspace and admin data, exports and imports, notes and live socket updates behave the same, and every API response is byte for byte identical. The only differences were in how non-English text gets saved to the database, where the standard encoder is the one with bugs (missed searches and too small size limits). Turning it on by default gives every instance the speedup measured in #27583 (live socket updates encode 17x and decode 3x faster), and ENABLE_ORJSON=false keeps the old encoder. --- backend/open_webui/env.py | 2 +- backend/open_webui/main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index dc160e1592..275e254957 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -159,7 +159,7 @@ ENABLE_DB_MIGRATIONS = os.getenv('ENABLE_DB_MIGRATIONS', 'True').lower() == 'tru # Swap the JSON encoder/decoder used across the app (HTTP request bodies, JSONResponse # bodies, upstream provider responses, socket.io payloads) from the stdlib `json` module # to orjson. Faster, but stricter: see open_webui/utils/json_codec.py for the differences. -ENABLE_ORJSON = os.getenv('ENABLE_ORJSON', 'False').lower() == 'true' +ENABLE_ORJSON = os.getenv('ENABLE_ORJSON', 'True').lower() == 'true' # Function to parse each section diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index ab9387e47f..694c62a543 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -502,7 +502,7 @@ async def lifespan(app: FastAPI): await publish_event(app, EVENTS.SYSTEM_SHUTDOWN_COMPLETED, source='system') -# Opt-in (ENABLE_ORJSON): orjson for request-body parsing and JSONResponse bodies; +# ENABLE_ORJSON: orjson for request-body parsing and JSONResponse bodies; # response_model routes keep FastAPI's Pydantic fast path either way. apply_orjson_http_json()