← 输入框|github.com|刷新
Skip to content

Question: can we move away from flyweight pattern? #366

Closed

Description

@yschimke

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.

Activity

  1. yschimke commented on Aug 9, 2017

    @yschimke
    MemberAuthor
  2. yschimke commented on Aug 9, 2017

    @yschimke
    MemberAuthor

    subtext: the frame flyweight pattern still trips me up after all this time, and it makes debuggers a hell of a lot less useful

  3. lexs commented on Aug 9, 2017

    @lexs
    Contributor

    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.

  4. tmontgomery commented on Aug 11, 2017

    @tmontgomery
    Contributor

    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.

  5. robertroeser commented on Aug 11, 2017

    @robertroeser
    Member

    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.

  6. robertroeser commented on Aug 23, 2017

    @robertroeser
    Member

    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.

  7. yschimke commented on Aug 23, 2017

    @yschimke
    MemberAuthor

    @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.

  8. robertroeser commented on Sep 19, 2017

    @robertroeser
    Member

    @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

  9. robertroeser commented on Nov 12, 2017

    @robertroeser
    Member

    #444

    Makes it so you can use ByteBufs directly, but maintain backward compatibility. Call .frameDecoder(Frame::retain) in RSocketFactory to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions