mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-02 19:08:15 -05:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user