Repository navigation
Use partysocket in favour of react-use-websocket, remove batching - #402
Conversation
|
Did you try a benchmark with both batching and partysocket? On my machine, firefox profiler is saying this branch is using about 2-3x more CPU when looking at HIFI with hidden blocks expanded. I think it might still be worth using |
|
I didn't. batching is always going to be better because it's skipping any rendering of any compoents for however many messages come through in 1 second. I was hoping that this change would be "good enough" to avoid the extra complexity of batching. I tested this on a simulated low end phone and it keeps up with updates on HIFI with hidden blocks, UI isn't laggy or anything, so deemed that to be OK without it. also, this gets rid of the initial page load delay where it says everything's unreachable while the batching is filling up the 0th batch. Partysocket does look like it's a bit more widely used too! |
This PR removes the batching behaviour we added to solve performance issues a while ago, particularly with instruments with large numbers of blocks. I got claude to benchmark this with a softioc with 200 PVs+pvws as well as the real instance. Also smoke tested with chrome's throttler to simulate a low-end phone with a slow 4g connection and it kept up with updates.
react-use-websocket uses flushSync() (see issue here) which causes a re-render of the entire component when a message is received - this is a big performance issue as we only really want to update whichever block has updated. The batching helped because it was rendering unchanged components for the time the batch was "filling up" but I don't think it's needed if we're being more cleverer about what we're re-rendering. Batching is obviously still better for raw performance but gives the trade-off of slower updates.
I also looked at using jotai atoms but this only really helped marginally - i don't think it's worth the extra dependency. We could use an empty filter as a workaround (
filter: () => false) and withoutlastMessagewhich we don't use now as we set everything up inonOpen().partysocketseems to be more popular according to npm stats regardless.benchmarks
Setup:
Variants:
main: the current code, with a 1 s batching queue.main(react-use-websocket + 1 s batching)main(react-use-websocket + 1 s batching)main(react-use-websocket + 1 s batching)Metrics:
Findings:
react-use-websocket wraps every message in
flushSync, forcing a synchronous React render per message.flushSynccombined with re-rendering the whole tree per message. It's unusable even at 200 blocks: 10 s+ lag and about 5 fps.main, this PR has 3–4× lower latency and lower lag at every size. Batching still gets more fps at 200–500 blocks, because the phone is now limited by layout and paint rather thanscript.
Block, so we dropped the extra dependency.