gaukas / watm

WebAssembly Transport Module
GNU General Public License v3.0
1 stars 0 forks source link

tinygo/v0: use `poll_oneoff` in poll #2

Closed gaukas closed 7 months ago

gaukas commented 7 months ago

Current implementation of both fairPoll and unfairPoll has employed busy polling methods, which actively tries reading from non-blocking file descriptors and see if anyone returns other than EAGAIN.

While this approach works, it creates performance overhead which could in theory max out a processor core, slowing down the device as well as draining batteries (especially on mobile phone platforms).

Instead a better approach is using a poll-like approach (as mentioned in #1). WASI Preview 1 defines poll_oneoff which behaves like poll and blocks until at least an event subscribed to is triggered. (It does not support specifying a timeout, but we can subscribe to a clock event instead.)

Therefore, we should consider importing poll_oneoff or use the existing implementation. TinyGo is allegedly importing poll_oneoff but we are not seeing any non-trivial use case. golang/go is also importing poll_oneoff when implementing the netpoll function set on wasip1. We could possibly build a similar wrapper.