snapview / tokio-tungstenite

Future-based Tungstenite for Tokio. Lightweight stream-based WebSocket implementation
MIT License
1.88k stars 236 forks source link

Performance boost implementing `poll_write_vectored` and rustls 0.23 #322

Closed stormshield-gt closed 8 months ago

stormshield-gt commented 8 months ago

With new write-through API functionality of rustls 0.23 (https://github.com/rustls/rustls/pull/1640), this library can implement poll_write_vectored on stream and gain a significant performance boost.

Basically, this is the same issue as in tokio-rustls https://github.com/rustls/tokio-rustls/issues/26, which has a current PR to solve it https://github.com/rustls/tokio-rustls/pull/45

daniel-abramov commented 8 months ago

This won't help in our particular case as our underlying streams don't provide an implementation of vectored writes - this is caused by some known issues such as us relying solely on tungstenite-rs which was written under an assumption that streams implement Read + Write, instead of providing a sans-io implementation. But once we update the API surface of the tungstenite-rs, this would certainly be possible!

This is also one of the reasons why alternatives such as fastwebsockets are more performant.

agalakhov commented 8 months ago

This could indeed be implemented with future versions of Rust. One needs something like https://rust-lang.github.io/rfcs/1210-impl-specialization.html in order to switch between implementations for different streams. With that, one could implement a simple I/O for generic streams and scatter-gather I/O for less generic ones. With the current version of Rust it is however impossible to use the vectored feature of some advanced streams without losing the possibility to work with any stream that has Read+Write.