GithubHelp home page GithubHelp logo

Comments (7)

Thomasdezeeuw avatar Thomasdezeeuw commented on August 22, 2024

You can use the std::io::Read implementation for this. It makes a read(2) system call instead of send(2), but those behave the same way with the arguments we pass.

As for the recv method itself, it will continue to use to uninitialised bytes to not force the caller to initialise them only to overwrite them again. Using the readbuf API would be nice, but that's not stable, so not usable by this crate.

from socket2.

keepsimple1 avatar keepsimple1 commented on August 22, 2024

thanks for your reply. I should have, but forgot to clarify that, what I needed is .recv_from() which is in the same boat as .recv() (and doc forwarded to .recv()) .

Currently I'm using read(), but won't be able to get the source IP.

from socket2.

Thomasdezeeuw avatar Thomasdezeeuw commented on August 22, 2024

For recv_from we don't have a version that uses &[u8]. We've had attempts to to add them, e.g. #246, but it basically came down to coping all the recv methods only to call the version with uninitialised bytes, so it wasn't worth the maintenance burden.

from socket2.

keepsimple1 avatar keepsimple1 commented on August 22, 2024

I guess it was probably a tough decision for you the maintainers, but I was curious how much performance gain of the version with uninitialized buffer. Among all socket2 users, how many percent of users prefer to use this version of uninitialized buffer?

It's probably impossible to change it back, but I just felt it's not a worthy trade-off, i.e. disabling / crippling common use cases for (IMO) edge cases.

from socket2.

Thomasdezeeuw avatar Thomasdezeeuw commented on August 22, 2024

I guess it was probably a tough decision for you the maintainers, but I was curious how much performance gain of the version with uninitialized buffer. Among all socket2 users, how many percent of users prefer to use this version of uninitialized buffer?

I don't really have performance test ready, but here an example of using uninitialised memory for HTTP headers: 5225225/hyper@325b7e5 that saves ~5%.

It's probably impossible to change it back, but I just felt it's not a worthy trade-off, i.e. disabling / crippling common use cases for (IMO) edge cases.

It's not really the common case though. Most users of this library use advance features, where not initialising memory is considered the common case.

from socket2.

keepsimple1 avatar keepsimple1 commented on August 22, 2024

I don't really have performance test ready, but here an example of using uninitialised memory for HTTP headers: 5225225/hyper@325b7e5 that saves ~5%.

5% seems to me really not worth changing a safe Rust code to unsafe Rust code, especially if in the grand scheme of a bigger system.

from socket2.

Thomasdezeeuw avatar Thomasdezeeuw commented on August 22, 2024

5% is a lot actually. That's massive improvement. Especially for a 1 line change that is documented as supported by socket2.

I think the best way forward is the read buf, which is still unstable. So closing in favour of #366.

from socket2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.