[Feature?]: Websocket for SolidStart/SolidJS, instead of fetch
Duplicates
- [X] I have searched the existing issues
Latest version
- [X] I have tested the latest version
Summary 💡
I did search for issues, but I'm not sure if this is possible already or not.
Looking at the Network tab in Development Tools in the production/development build of a SolidStart, it seems that the calls to the server are fetch calls (to the /_server).
I think there would be performance gains to be had here if this was done with websockets. I.e. open the connection when the first request is made and use that with every page change. When the page changes are client-side, it should be possible to use websockets.
Motivation 🔦
- Connection always open
- HTTP request overhead will not exist
It is the contrary actually, and not all web services has built-in websockets support. There isn't really any benefit on switching towards it, in fact, fetch provides more pros than cons.
open the connection when the first request is made and use that with every page change
fun fact: this is what http/2 solves
I did some tests (https://github.com/ile/fetch-ws-test) to a server located in the same country.
Running 100 requests for each method, 2 times...
Run 1:
HTTP Fetch with Keep-Alive:
Average: 18.980 ms
Min: 17.000 ms
Max: 35.000 ms
HTTP Fetch without Keep-Alive:
Average: 33.530 ms
Min: 19.000 ms
Max: 38.000 ms
WebSocket:
Average: 14.640 ms
Min: 14.000 ms
Max: 16.000 ms
Run 2:
HTTP Fetch with Keep-Alive:
Average: 19.030 ms
Min: 17.000 ms
Max: 38.000 ms
HTTP Fetch without Keep-Alive:
Average: 33.160 ms
Min: 19.000 ms
Max: 38.000 ms
WebSocket:
Average: 14.700 ms
Min: 13.000 ms
Max: 17.000 ms
Average Results Across All Runs:
keepAlive:
Average: 19.005 ms
Min: 17.000 ms
Max: 38.000 ms
noKeepAlive:
Average: 33.345 ms
Min: 19.000 ms
Max: 38.000 ms
webSocket:
Average: 14.670 ms
Min: 13.000 ms
Max: 17.000 ms
It's not a huge difference between keep-alive fetch and websocket. Not totally without a difference.
fun fact: this is what http/2 solves
I know that "fun fact", but at least before the fetch keep-alive was unreliable in Firefox. https://stackoverflow.com/questions/67754620/fetch-keep-alive-is-not-working-as-expected