You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question: can we move away from flyweight pattern? #366
My contention, if we move away from the single concrete implementation of Frame, and various flyweights e.g. ErrorFrameFlyweight. We could have extremely light implementations of Frame subtypes like ErrorFrame that would just wrap a ByteBuf, which was then recycled. The cost of any particular Frame instance (ignoring the ByteBuf) is roughly equivalent to any one of the million of temporary objects we create with all the syntactic sugar that happens in reactor operations.
We don't get much from Frame being recycleable, since the main cost if the ByteBuf within.
By moving to a more idiomatic model with Frame subtypes, we would get type safety and a more discoverable API for ourselves. n.b. these are generally internal so mostly I don't think this affects a user of the ReactiveSocket API.
I would say try it out in a PR and see how it feels and acts. On data reception and sending, it should not be necessary to allocate a new ByteBuf or Frame. A core benefit of a flyweight is, just as in a C/C++ struct, to be reused by wrapping it (or casting it) onto a buffer.
Originally, Frame was allocated and pooled due to how tests and integration was done. It may no longer need to be pooled and might best be handled as thread-local instead. Less than ideal, but better than being pooled.
I'd prefer to keep the Flyweights. I think the thing that would make this easier and create less garbage would be exposing ByteBuf in the Payload signature. @rdegnan might have some thoughts on this.
I felt we ended with java.io.ByteBuffer as the one true abstraction supported by all other transport dependencies anyway, like Agrona or Netty.
For this issue I'm more talking about us having already given up on type safety by passing around Frames (buffer with access to metadata, data and flags). I would prefer we passed around subtypes of Frame like SetupFrame. I dislike using SetupFrameFlyweight and Frame.Setup.
@yschimke I understood. I just think if we want to do something with the frames are best bet would be to make the Payloads typed. Zero copy isn't worked properly. It would be nice to make Payload typed, and then you could do something Payload<ByteBuf>, Payload<ByteBuffer>, Payload<DirectBuffer> etc depending on the transport.
@tmontgomery the frames are being recycled using io.netty.util.Recycler tied to the ByteBuf.release() calls
Activity
yschimke commentedon Aug 9, 2017
cc @benjchristensen @stevegury @tmontgomery @robertroeser @rdegnan
yschimke commentedon Aug 9, 2017
subtext: the frame flyweight pattern still trips me up after all this time, and it makes debuggers a hell of a lot less useful
lexs commentedon Aug 9, 2017
I'd be strongly in favor of this, and honestly it would still be a flyweight given that the data is stored in the buffer still.
tmontgomery commentedon Aug 11, 2017
I would say try it out in a PR and see how it feels and acts. On data reception and sending, it should not be necessary to allocate a new ByteBuf or Frame. A core benefit of a flyweight is, just as in a C/C++ struct, to be reused by wrapping it (or casting it) onto a buffer.
Originally, Frame was allocated and pooled due to how tests and integration was done. It may no longer need to be pooled and might best be handled as thread-local instead. Less than ideal, but better than being pooled.
robertroeser commentedon Aug 11, 2017
I'd prefer to keep the Flyweights. I think the thing that would make this easier and create less garbage would be exposing ByteBuf in the Payload signature. @rdegnan might have some thoughts on this.
robertroeser commentedon Aug 23, 2017
We should look into doing something like lmdbjava does:
https://github.com/lmdbjava/lmdbjava/blob/master/src/main/java/org/lmdbjava/BufferProxy.java
We can make the type of buffer being returned specific to the underlying transport.
yschimke commentedon Aug 23, 2017
@robertroeser I think that is more related to this discussion #123
I felt we ended with java.io.ByteBuffer as the one true abstraction supported by all other transport dependencies anyway, like Agrona or Netty.
For this issue I'm more talking about us having already given up on type safety by passing around Frames (buffer with access to metadata, data and flags). I would prefer we passed around subtypes of Frame like SetupFrame. I dislike using SetupFrameFlyweight and Frame.Setup.
robertroeser commentedon Sep 19, 2017
@yschimke I understood. I just think if we want to do something with the frames are best bet would be to make the Payloads typed. Zero copy isn't worked properly. It would be nice to make Payload typed, and then you could do something Payload<ByteBuf>, Payload<ByteBuffer>, Payload<DirectBuffer> etc depending on the transport.
@tmontgomery the frames are being recycled using io.netty.util.Recycler tied to the ByteBuf.release() calls
robertroeser commentedon Nov 12, 2017
#444
Makes it so you can use ByteBufs directly, but maintain backward compatibility. Call
.frameDecoder(Frame::retain)in RSocketFactory to use it.