-
Notifications
You must be signed in to change notification settings - Fork 353
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
Pick a single ByteBuffer implementation for all public APIs #123
Comments
IIRC the reason why we stick to |
@stevegury Yes we need a @yschimke you are not the only one who have issues with I think the primary benefit of using I would like to propose that we stop using JDK buffer API and define a restricted, usable buffer API for This may sound extreme to some but it will provide the following benefits:
Just to be clear, I don't believe we ever need to provide any implementation of our buffer API as we always read/write what is provided by the user/transport I think there may be cases where we would trade some performance for clarity and maintainability of code but I think we should have strong data points that it indeed is the case. In absence of which, I would like to prefer clarity over micro-optimizations (assuming individual transports have done the optimizations required) |
This is pretty much what Finagle did https://github.com/twitter/util/blob/develop/util-core/src/main/scala/com/twitter/io/Buf.scala Although personally, I'd be interested if we could survive with just Netty's buffers and the handover to agrona still be efficient. |
@yschimke we can chose netty's buffer as the library for ReactiveSocket but I think it is too broad an API for our use and has ref-counting as a core part of the API, which I am unsure of whether we need it or not. |
I'm not a fan of locking into to Netty as a dependency. |
To be clear, I really like Netty, but ReactiveSocket should not require someone using Netty. There are plenty of other options out there. For example, if using Aeron as the transport, someone shouldn't have to bring along Netty for the ride just for the Buffer type. And if someone is using one of the many alternatives to Netty for TCP, including just standard JDK libraries, again, they shouldn't have to bring along Netty. Even Agrona is a dependency I'd prefer not having as I strongly prefer zero-dependency libraries whenever possible. |
@benjchristensen so looks like you are inclined towards defining our own buffer abstraction or you prefer using JDK buffers? |
I'll start on commons-buffers using runtime classloading tricks to choose an implementation at runtime :) I kid... I kid... |
Whichever works better. Our own buffer abstraction as an interface may work best as it avoids the concrete implementation of JDK. Can we have the interface behave similar to DuplexConnection where we interact with just the interface, and then the binding implementation is provided by whatever provides DuplexConnection? In other words, a ReactiveSocket can't be created without a concrete DuplexConnection, and without a concrete Buffer factory? |
The first part is what my thinking was that we don't have to instantiate a buffer ourselves which removes the necessity of providing a factory. Although, users would have to provide |
@yschimke I think that is a good idea (#maniacalLaughter) |
@yschimke |
Also - we already chose ByteBuffer |
This seems pretty good now Agrona byte buffer usage seems limited to
|
Currently java.nio.ByteBuffer is predominantly used for public APIs. Have a few issues, e.g. you really need to defensively shallow copy with bb.duplicate(). Also not always clear whether the intention is to use position/limit that caller provided, or treat it as a byte[] holder.
Some public APIs e.g. Frame expose Agrona and its used in metadata package. The netty packages use Netty's buffer, but mostly this is internal.
A single buffer API should be used which would make it easier to be sure that code is correct.
The text was updated successfully, but these errors were encountered: