State pickle compression#4430
Conversation
|
@masenf we could add a compression threshold for small payloads. WDYT? Edit: I just implemented it |
|
While this can help a lot with big states, I think frontend payload compression could have an even bigger impact. Especially with slow connections, f.e. on mobile. Pickle payloads already benefit from referential serialization, json/ws does nothing similar. In fact, currently, the ws payloads are not compressed at all. Socketio only compresses in long-polling mode, which is only used for the initial connection and incompatible with gunicorn (I disabled it in #4441) |
|
@masenf i was just brainstorming in that comment and only read some docs. I did not test it. Just confirmed your wireshark capture, seems to be compressed by default. Interesting, i wonder where this happens, maybe i'll need to scroll trough some code to understand it. |
|
It is just not documented very well. python-socketio uses python-engineio which uses simple-websocket, which has compression enabled with hardcoded default settings since miguelgrinberg/simple-websocket@9277e67 |
|
In the JS version of socket.io,
|
|
Very intersting, thanks for sharing. Maybe some (optimized) reflex apps could even benefit from disabling that compression. For big states/apps it's probably good that it's enabled. However with python-socketio reflex has no way to control this. Maybe we can adress that in the future. However we are getting a bit off-topic in this PR which is about pickle compression. Maybe i'll create an Issue to further discuss our performance impact and ideas for websocket compression. |
6ae0ad0 to
e2a58c2
Compare
CodSpeed Performance ReportMerging #4430 will not alter performanceComparing Summary
|
|
Thank you for contributing to Reflex. I am closing this old or stale PR for now, but please refresh and reopen it if you believe this issue is still relevant. |


Turns out, state compression can make a big difference. Of course depending on the circumstances (Redis Bandwidth, Latency, State Size, ...). You can run
REDIS_URL=redis_host:redis_port pytest benchmarks/benchmark_pickle.pyto test it on your machine.Will probably evaluate other compression algorithms (especially those integrated into python) in a followup and introduce a
ReflexCompressorInterface.