GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — LengthFieldBasedFrameDecoder Class Can be optimized · Issue #12171 · netty/netty

LengthFieldBasedFrameDecoder Class Can be optimized #12171

New issue
Copy link
New issue
Copy link
Closed
#12173
Closed
LengthFieldBasedFrameDecoder Class Can be optimized#12171
#12173
Copy link
Milestone
4.1.76.Final

Description

@AbcCreatorDeep
AbcCreatorDeep
opened on Mar 15, 2022
Issue body actions

Expected behavior

LengthFieldBasedFrameDecoder . decode(ChannelHandlerContext ctx, ByteBuf in) method,Can be optimized - Can we keep frameLengthInt in instance variable? so , When there is not enough data in the buffer, the length of the data frame does not need to be recalculated at the next decoding。code:

// LengthFieldBasedFrameDecoder class
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
... // check maxFrame
int frameLengthInt = (int) frameLength;
if (in.readableBytes() < frameLengthInt) { // When there is not enough data in the buffer, The above code will be executed again, and I just need to wait for the buffer to contain enough data . In fact, we can save the frameLengthInt variable without having to
return null;
}
... // extract frame
}

Actual behavior

When there is not enough data in the buffer, the length of the data frame recalculate at the next decoding

Steps to reproduce

Non-Required

Minimal yet complete reproducer code (or URL to code)

Non-Required

Netty version

4.1.X

JVM version (e.g. java -version)

Non-Required

OS version (e.g. uname -a)

Non-Required

Activity

  1. normanmaurer commented on Mar 15, 2022

    @normanmaurer
    normanmaurer
    on Mar 15, 2022
    Member
    More actions

    @NickleHuang please provide a PR :)

  2. normanmaurer
    closed this as completedin #12173on Mar 15, 2022
  3. normanmaurer
    added a commit that references this issue on Mar 15, 2022

    Length field based frame decoder can be optimized (#12173)

    This issue will close once commit 824a0b8 is merged into the '4.2' branch.
    824a0b8
  4. normanmaurer
    added this to the 4.1.76.Final milestone on Mar 15, 2022
  5. normanmaurer
    added a commit that references this issue on Mar 15, 2022

    Length field based frame decoder can be optimized (#12173)

    This issue will close once commit 457faee is merged into the '4.2' branch.
    457faee
  6. raidyue
    added a commit that references this issue on Jul 8, 2022

    Length field based frame decoder can be optimized (netty#12173)

    This issue will close once commit 110bcaf is merged into the 'master' branch.
    110bcaf
  7. bigT commented on Aug 4, 2022

    @bigT
    bigT
    on Aug 4, 2022
    More actions

    First off, thanks for making and maintaining Netty. Don't take it as a complaint but as a heads up.

    This is a braking change. It regresses expected behaviour of the LengthFieldBasedFrameDecoder.

    The protected long getUnadjustedFrameLength(ByteBuf buf, int offset, int length, ByteOrder order) is marked protected it is deemed a point of extension and therefore is a part of the public API. Nothing in the documentation of the method states what behaviour should be expected by the implementors i.e. whether it is expected to be called once or multiple times. However, prior to the change it was invoked multiple time. As such it is now (was) part of the expected, albeit undocumented, behaviour.

    I have an ASN1 frame decoder, that broker after a recent upgrade that I traced to this change. ASN1 allows frames of be variable length, the length field itself is variable width. Prior to the change, if the buffer contained partial frame that truncated the length filed, it was possible to first return a frame length that would ensure enough bytes were read to decode the length header. With a subsequent call to the getUnadjustedFrameLength decoding a full frame length. I.e. it was possible to progressively decode the length of the frame. After the change this is no-longer possible.

    Not a show stopper, but I can no-longer use provided LengthFieldBasedFrameDecoder.

    Cheers!

  8. AbcCreatorDeep commented on Aug 4, 2022

    @AbcCreatorDeep
    AbcCreatorDeep
    on Aug 4, 2022
    Author
    More actions

    maybe you can revert frameLengthInt to -1 ,read your new frame , But at the moment, there is no such mechanism,you can override getUnadjustedFrameLength and revert frameLengthInt to -1 . make frameLengthInt property to protected?

  9. bigT commented on Aug 4, 2022

    @bigT
    bigT
    on Aug 4, 2022
    More actions

    I've decided that I will override protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception instead and re-use as much of the base class as possible. However most of the static utility methods are private so it makes it hard.

    If you decide to keep the change, it may be worth updating the documentation to let folks know what is the expected behaviour of the protected methods in the class.

  10. AbcCreatorDeep commented on Aug 4, 2022

    @AbcCreatorDeep
    AbcCreatorDeep
    on Aug 4, 2022
    Author
    More actions

    @normanmaurer man,I've added an method that allows users to repeatedly read frames by overwriting getUnadjustedFrameLength

  11. AbcCreatorDeep commented on Aug 4, 2022

    @AbcCreatorDeep
    AbcCreatorDeep
    on Aug 4, 2022
    Author
    More actions

    i add resetFrameLengthInt method,you can call it to repeat read frame

  12. bigT commented on Aug 4, 2022

    @bigT
    bigT
    on Aug 4, 2022
    More actions

    See my comments on the pull request.

  13. franz1981
    added 2 commits that reference this issue on Aug 22, 2022

    Length field based frame decoder can be optimized (netty#12173)

    This issue will close once commit 18428ef is merged into the '4.1' branch.
    18428ef
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

      • 4.1.76.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.