Skip to content

Commit 6deefd4

Browse files
committed
use orjson
1 parent 2a13180 commit 6deefd4

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ Using the following categories, list your changes in this order:
3838

3939
## [3.3.2] - 2023-08-09
4040

41+
### Added
42+
43+
- ReactPy Websocket will now decode messages via `orjson` resulting in an ~6% overall performance boost.
44+
4145
### Changed
4246

4347
- Changed implementation of `REACTPY_BACKHAUL_THREAD` to attempt increased performance compatibility.

requirements/pkg-deps.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ django >=4.1.0
33
reactpy >=1.0.0, <1.1.0
44
aiofile >=3.0
55
dill >=0.3.5
6+
orjson >=3.0.0
67
typing_extensions

src/reactpy_django/websocket/consumer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Any, MutableMapping, Sequence
1111

1212
import dill as pickle
13+
import orjson
1314
from channels.auth import login
1415
from channels.db import database_sync_to_async
1516
from channels.generic.websocket import AsyncJsonWebsocketConsumer
@@ -107,6 +108,14 @@ async def dispatch(self, message):
107108

108109
return await super().dispatch(message)
109110

111+
@classmethod
112+
async def decode_json(cls, text_data):
113+
return orjson.loads(text_data)
114+
115+
@classmethod
116+
async def encode_json(cls, content):
117+
return orjson.dumps(content).decode()
118+
110119
async def run_dispatcher(self):
111120
"""Runs the main loop that performs component rendering tasks."""
112121
from reactpy_django import models

0 commit comments

Comments
 (0)