#tick #executor #events #ticker #callback #web #node

wasm-ticker

Non-block tick executor for WebAssembly Rust

3 releases

0.1.2 Sep 4, 2024
0.1.1 Sep 4, 2024
0.1.0 Sep 3, 2024

#348 in WebAssembly

48 downloads per month

MIT license

29KB
544 lines

wasm-ticker

Non-block tick executor for WebAssembly Rust.

Ticker callbacks queue as Tasks to JavaScript event loop. Instead of Microtasks or just stacking in, Tasks won't block current host context and UI rendering thread. See also https://developer.mozilla.org/docs/Web/API/HTML_DOM_API/Microtask_guide/in_depth

Ticker API Platform Interval
Browser / Node
MessageChannelTicker Channel Messaging * >4µs / <1µs
ImmediateTicker setImmediate Node ~1µs
TimeoutTicker setTimeout * ~4ms / ~14ms
AnimationFrameTicker requestAnimationFrame Browser According to device
AutoTicker One of above * N/A

Speed Tests:

wasm-pack test --node --release --test speed
# MessageChannelTicker: 10726000/10s, interval: 932ns
# ImmediateTicker: 9051901/10s, interval: 1.104µs
# TimeoutTicker: 664/10s, interval: 15.06024ms
# AutoTicker: 9879000/10s, interval: 1.012µs

wasm-pack test --chrome --release --test speed # with devtools closed
# MessageChannelTicker: 2359423/10s, interval: 4.238µs
# TimeoutTicker: 2140/10s, interval: 4.672897ms
# AnimationFrameTicker: 1438/10s, interval: 6.954102ms
# AutoTicker: 2405336/10s, interval: 4.157µs

wasm-pack test --chrome --release --test speed # with devtools opened
# MessageChannelTicker: 847715/10s, interval: 11.796µs
# TimeoutTicker: 2134/10s, interval: 4.686035ms
# AnimationFrameTicker: 1441/10s, interval: 6.939625ms
# AutoTicker: 860572/10s, interval: 11.62µs

Dependencies

~7.5–10MB
~182K SLoC