MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / maybe_spawn_encode

Function maybe_spawn_encode

crates/client-api/src/routes/subscribe.rs:1775–1781  ·  view source on GitHub ↗

Run `encode` on Rayon when the payload is expected to be large. Small payloads stay on the async task to avoid Rayon scheduling overhead.

(is_large: bool, encode: impl FnOnce() -> T + Send + 'static)

Source from the content-addressed store, hash-verified

1773///
1774/// Small payloads stay on the async task to avoid Rayon scheduling overhead.
1775async fn maybe_spawn_encode<T: Send + 'static>(is_large: bool, encode: impl FnOnce() -> T + Send + 'static) -> T {
1776 if is_large {
1777 spawn_rayon(encode).await
1778 } else {
1779 encode()
1780 }
1781}
1782
1783/// Measure serialization/compression time for one websocket payload.
1784fn time_encode<T>(encode: impl FnOnce() -> (InUseSerializeBuffer, T)) -> (Duration, InUseSerializeBuffer, T) {

Callers 2

ws_encode_messageFunction · 0.85

Calls 2

spawn_rayonFunction · 0.85
encodeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…