3 ms·
The most efficient way of executing a non-I/O function is to just use the thread stack to store its data and optimize it for speed rather than for using little
by devit 7y ago
The most efficient way of executing a non-I/O function is to just use the thread stack to store its data and optimize it for speed rather than for using little stack space.
However, for functions that can block indefinitely on I/O, then such an approach would mean keeping an inefficiently-large stack around indefinitely.
Hence, the better solution is to put the data on the heap, ideally in a manually engineered structure (i.e. "manual implementation of futures"), or for more ergonomics in one efficiently designed by the compiler (i.e. async/await).