brettwooldridge / NuProcess

Low-overhead, non-blocking I/O, external Process implementation for Java
Apache License 2.0
712 stars 84 forks source link

Thoughts on using netty ByteBuf over java ByteBuffer #68

Closed cdancy closed 7 years ago

cdancy commented 7 years ago

Netty allows for the library to be used in a generic fashion rather than for standing up a server/client. As such one could use their ByteBuf as a replacement for java's ByteBuffer for all the reasons documented in the link. Something we could leverage here? Thoughts?

https://github.com/netty/netty/wiki/Using-as-a-generic-library

brettwooldridge commented 7 years ago

@cdancy Thanks for using NuProcess.

There are a number of major projects that use NuProcess that are fairly adamant about not pulling in other dependencies.

There are many alternatives to ByteBuffer out there, including netty's and square/okio. The number of users who use square/okio is probably much greater than those who use netty as a generic library, so arguably that would be the better choice.

However, NuProcess' relatively simple API and interaction model simply doesn't impose much burden on the user with respect to ByteBuffer interaction, and none of the GC problems that the Netty project encountered have surfaced for users of NuProcess, so it is difficult to find justification to switch.

The ByteBuffer instances in NuProcess essentially live for the life of a process, so the amount of allocation and GC is extremely low. With the performance issue off the table, that leaves only the somewhat clunky interaction model of ByteBuffer -- with flip() and whotnot -- which is not so clunky because of our relatively light interaction model and the fact that NuProcess does half of the flips for the user anyway.

cdancy commented 7 years ago

Fair enough and thanks for chiming in. Yes I like the library as it makes working with processes stupid simple and efficient.

Having actually worked with netty/okio previously, for nio related use-cases, I can say (which I believe is well known at this point) that while okio is easier to plugin and use netty's ByteBuf is just more efficient and performant all around. Though I agree with your statement in that it just may not be worth it.