perf: separate proxy message handling into a `Worker`
Unless there is a way to do #48 (closed), running onmessage
handlers on a separate thread should reduce latency by allowing main thread code and onmessage
to be executed at the same time, not sequentially. I think a Worker
should be created for each ProxyPair
(maybe even two workers, for client -> relay and relay -> client, but I'm not sure if it's possible to share a single WebSocket
/RTCPeerConnection
between two workers), although right now the default maxNumClients
is 1
anyway.
Here's the current message passing code: https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake-webext/-/blob/4b56f7a350ef78ac2f8888cdd15d529dada30f72/proxypair.js#L227-239
FYI RTCDataChannel
s are transferable objects (but it's not implemented in the majority of browsers yet) (but I'm not saying that the implementation would necessarily have to make use of that fact).