You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
io::Error::new will always allocate. This isn't a huge deal when the error represents an actual error case, however I/O "errors" are used often to signal termination in hot paths and the allocation can cause significant bottleneck.
One example is with non-blocking I/O, io::ErrorKind::WouldBlock is used to signal that the source is not read to process the op. Suffering an allocation for this very common case is not acceptable.
However, WouldBlock is not the only case. Another common case that I am hitting is using io::ErrorKind::WriteZero being triggered when calling write_all to io::Write implementations that are backed by memory (vs. an I/O type).
In general, there should be a way to construct I/O errors without allocating.
Add conversions from `io:ErrorKind` to `io::Error`
Filing to help with discussion around the possibility of doing this.
Current changes are clearly backwards incompatible, but I think adding a new function (with a bikeshed on naming) like `Error::new_str` should be possible (or some other way of specializing the string error message case) to fix#36658.
io::Error::new
will always allocate. This isn't a huge deal when the error represents an actual error case, however I/O "errors" are used often to signal termination in hot paths and the allocation can cause significant bottleneck.One example is with non-blocking I/O,
io::ErrorKind::WouldBlock
is used to signal that the source is not read to process the op. Suffering an allocation for this very common case is not acceptable.To work around this, Mio provide a helper to construct a
WouldBlock
error without the allocation: https://github.com/carllerche/mio/blob/master/src/io.rs#L40-L49.However,
WouldBlock
is not the only case. Another common case that I am hitting is usingio::ErrorKind::WriteZero
being triggered when callingwrite_all
toio::Write
implementations that are backed by memory (vs. an I/O type).In general, there should be a way to construct I/O errors without allocating.
/cc @alexcrichton
The text was updated successfully, but these errors were encountered: