try orjson#6116
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
Greptile OverviewGreptile SummaryThis PR migrates from Python's standard Key changes:
Issues found:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant App as Reflex App
participant Socket as WebSocket Handler
participant Format as format.py
participant OrJSON as orjson (optional)
participant StdJSON as json (stdlib)
App->>Format: orjson_dumps(data)
Format->>Format: try import orjson
alt orjson installed
Format->>OrJSON: orjson.dumps()
OrJSON-->>Format: bytes
Format-->>App: str (decoded)
else orjson not installed
Format->>StdJSON: json.dumps()
StdJSON-->>Format: str
Format-->>App: str
end
Socket->>Format: orjson_loads(json_str)
Format->>Format: try import orjson
alt orjson installed
Format->>OrJSON: orjson.loads()
OrJSON-->>Format: dict/list
Format-->>Socket: parsed data
else orjson not installed
Format->>StdJSON: json.loads()
StdJSON-->>Format: dict/list
Format-->>Socket: parsed data
end
Note over Socket: Exception handler catches<br/>json.JSONDecodeError<br/>but orjson raises<br/>orjson.JSONDecodeError
|
|
the issue with orjson is that we lose NaN handling which is relevant for numpy, which is why we were using JSON5 as well |
|
Yeah, that's why i did not update it in all places |
…llback Happy path uses native JSON.parse; the catch rewrites Python"s bare Infinity/-Infinity/NaN tokens outside string literals before retrying, so only payloads that actually contain specials pay the extra cost. NaN has no JSON literal and becomes null (matches JSON.stringify).
…o null Swap bare NaN for a sentinel string before JSON.parse and revive it back to a real NaN so Python-side float(nan) round-trips to the frontend.
|
related #6339 |
Apply orjson_dumps/orjson_loads helpers to the new reflex_base package locations after upstream's restructuring.
bed6d7b to
7555e7b
Compare
No description provided.