erickt / rust-zmq

Rust zeromq bindings.
Apache License 2.0
900 stars 194 forks source link

Take advantage of "zero-copy" techniques from zmq blog #139

Open rotty opened 7 years ago

rotty commented 7 years ago

See http://zeromq.org/blog:zero-copy. This may also make the Sendable trait and wrapping zmq_send_const (see #119) unnecessary, as it should be possible to provide more efficient implementations of Into<Message> for &'static [u8]. Even without specialization, we could provide an efficient implementation of From<Vec<u8>> for Message, i.e. one that moves data out of the vector and hands ownership over to zmq.

Before implementing this, it would be nice to add a basic micro-benchmark first as a baseline. Even better would be to transcribe a (hopefully) existing micro-benchmark employing "zero-copy", so Rust performance can be compared to C before and after implementing the optimization.

birkenfeld commented 7 years ago

Zero-copy is nice, but we have to consider the implications of callbacks from C - e.g. when the callback panics.

rotty commented 7 years ago

Yes, this a hairy subject to be approached with care and careful study of the nomicon.

Kobzol commented 5 years ago

Even without specialization, we could provide an efficient implementation of From<Vec<u8>> for Message, i.e. one that moves data out of the vector and hands ownership over to zmq.

This would be really nice, for example for serializing Protobuf objects into ZeroMQ messages.