Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate whether we can avoid copying the incoming ILP packet from the incoming HTTP request #554

Open
emschwartz opened this issue Dec 4, 2019 · 1 comment

Comments

@emschwartz
Copy link
Member

Most of Interledger.rs supports zero-copy ILP packet forwarding and manipulation. However, we are currently copying the packet as soon as it arrives from the HTTP request handled by warp. There may be a way to avoid having it copy the bytes in most cases.

warp doesn't expose the internal way the HTTP body is stored and instead provides the FullBody struct. Looking through the implementation a bit, it seems like there may a way to try turning the FullBody into the BytesMut needed by:

https://github.com/interledger-rs/interledger-rs/blob/ab94e2736eb616f40cb17d1eee672f899759a0ac/crates/interledger-http/src/server.rs#L61-L62

I haven't tried this but it looks like something along the following lines might work:

let chunk: hyper::Chunk = body.into_chunk();
let bytes: bytes::Bytes = chunk.into_bytes();
let body: bytes::BytesMut = bytes.try_mut().unwrap_or_else(BytesMut::from);

As described here, try_mut will turn the Bytes into a BytesMut without copying if there are no other references to the underlying data.

@emschwartz
Copy link
Member Author

This is blocked until we upgrade to a later version of warp that uses bytes >= v0.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant