rstudio / websocket

WebSocket client for R
https://rstudio.github.io/websocket/
Other
92 stars 19 forks source link

Run I/O on separate thread #62

Closed wch closed 4 years ago

wch commented 4 years ago

Closes #56. This PR runs the websocket I/O on a separate thread, instead of polling using later(). When a WebSocket exists but is idle, in a terminal it previously consumed about 2.5% CPU on my computer, and in RStudio it previously consumed 0.7%. Now it consumes 0% because the I/O thread's event loop works without using polling (I believe it uses something like epoll or select under the hood).

Also, with Chromote, it previously idled at ~6.5% CPU, but after this change and https://github.com/rstudio/chromote/pull/16, it idles at 0%.

TODO:

jcheng5 commented 4 years ago

Feel free to remove wsRestart and wsReset if you feel like it