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 — Branchless varint decoding by franz1981 · Pull Request #14050 · netty/netty

Conversation

@franz1981

@franz1981 franz1981 commented May 12, 2024

Copy link
Copy Markdown
Contributor

Motivation:

varint decoding fall shortly when input length is not predictable

Modification:

Implements branchless and batchy varint decoding

Result:

Better performance when inputs length is not predictable

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jchrys and Clownsw reacted with heart emoji
All reactions
  • ❤️ 2 reactions
@franz1981

franz1981 commented May 12, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

These are the results of the benchmark on my Ryzen box

Benchmark                                   (inputDistribution)  (inputs)  Mode  Cnt  Score   Error  Units
VarintDecodingBenchmark.oldReadRawVarint32                SMALL         1  avgt   10  1.547 ± 0.021  ns/op
VarintDecodingBenchmark.oldReadRawVarint32                SMALL       128  avgt   10  2.460 ± 0.023  ns/op
VarintDecodingBenchmark.oldReadRawVarint32                SMALL    128000  avgt   10  6.519 ± 0.092  ns/op
VarintDecodingBenchmark.oldReadRawVarint32                LARGE         1  avgt   10  3.936 ± 0.014  ns/op
VarintDecodingBenchmark.oldReadRawVarint32               MEDIUM         1  avgt   10  2.823 ± 0.022  ns/op
VarintDecodingBenchmark.oldReadRawVarint32               MEDIUM       128  avgt   10  2.791 ± 0.029  ns/op
VarintDecodingBenchmark.oldReadRawVarint32               MEDIUM    128000  avgt   10  7.799 ± 0.026  ns/op
VarintDecodingBenchmark.oldReadRawVarint32                  ALL         1  avgt   10  2.812 ± 0.043  ns/op
VarintDecodingBenchmark.oldReadRawVarint32                  ALL       128  avgt   10  2.847 ± 0.032  ns/op
VarintDecodingBenchmark.oldReadRawVarint32                  ALL    128000  avgt   10  8.094 ± 0.015  ns/op
VarintDecodingBenchmark.readRawVarint32                   SMALL         1  avgt   10  1.672 ± 0.040  ns/op
VarintDecodingBenchmark.readRawVarint32                   SMALL       128  avgt   10  2.547 ± 0.047  ns/op
VarintDecodingBenchmark.readRawVarint32                   SMALL    128000  avgt   10  6.572 ± 0.063  ns/op
VarintDecodingBenchmark.readRawVarint32                   LARGE         1  avgt   10  3.724 ± 0.016  ns/op
VarintDecodingBenchmark.readRawVarint32                  MEDIUM         1  avgt   10  3.348 ± 0.024  ns/op
VarintDecodingBenchmark.readRawVarint32                  MEDIUM       128  avgt   10  3.472 ± 0.035  ns/op
VarintDecodingBenchmark.readRawVarint32                  MEDIUM    128000  avgt   10  3.457 ± 0.051  ns/op
VarintDecodingBenchmark.readRawVarint32                     ALL         1  avgt   10  3.378 ± 0.041  ns/op
VarintDecodingBenchmark.readRawVarint32                     ALL       128  avgt   10  3.877 ± 0.041  ns/op
VarintDecodingBenchmark.readRawVarint32                     ALL    128000  avgt   10  8.413 ± 0.092  ns/op

The interesting ones are the the MEDIUM which assume to have >= 4 bytes to read (which is very likely), but a fair distribution of variable length varint (1, 2, 3, 4 bytes) .

Benchmark                                   (inputDistribution)  (inputs)  Mode  Cnt  Score   Error  Units
VarintDecodingBenchmark.oldReadRawVarint32               MEDIUM         1  avgt   10  2.823 ± 0.022  ns/op
VarintDecodingBenchmark.oldReadRawVarint32               MEDIUM       128  avgt   10  2.791 ± 0.029  ns/op
VarintDecodingBenchmark.oldReadRawVarint32               MEDIUM    128000  avgt   10  7.799 ± 0.026  ns/op
VarintDecodingBenchmark.readRawVarint32                  MEDIUM         1  avgt   10  3.348 ± 0.024  ns/op
VarintDecodingBenchmark.readRawVarint32                  MEDIUM       128  avgt   10  3.472 ± 0.035  ns/op
VarintDecodingBenchmark.readRawVarint32                  MEDIUM    128000  avgt   10  3.457 ± 0.051  ns/op

This last point on varint bytes could be not very realistic if most of the protobuf messages have "similar" length

NOTE Due to the highly accurate branch predictor of my Ryzen box, the number of inputs which makes the branch-misses to become relevant is ~128K, but as usual, YMMV.

NOTE 2: not very proud of this benchmark, because, due to the variable nature of input(s), avgs times can be less meaningful - and the same applies to perf counters (if -gc perfnorm is used...), because the number of instructions/branches etc etc for one of the algorithms depends on stop bit's position

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981
franz1981 force-pushed the 4.1_branchless_varint branch 2 times, most recently from 6117214 to d029cb3 Compare May 12, 2024 20:29
@franz1981
Branchless varint decoding
57defc5
Motivation:

varint decoding fall shortly when input length is not predictable

Modification:

Implements branchless and batchy varint decoding

Result:

Better performance when inputs length is not predictable
@franz1981
franz1981 force-pushed the 4.1_branchless_varint branch from d029cb3 to 57defc5 Compare May 12, 2024 21:12
franz1981
franz1981 commented May 12, 2024
View reviewed changes
Comment thread codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32FrameDecoder.java
return readRawVarint40(buffer, wholeOrMore);
}
int bitsToKeep = Integer.numberOfTrailingZeros(firstOneOnStop) + 1;
buffer.skipBytes(bitsToKeep >> 3);

@franz1981 franz1981 May 12, 2024

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed something very fun here: if I use readerIndex(int) it get slightly slower :(
which is very weird, because (FYI @chrisvest ), skipBytes check accessibility, while readerIndex(int), nope!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@chrisvest

chrisvest commented May 12, 2024

Copy link
Copy Markdown
Member

How much use is the protobuf codec seeing? I thought grpc-java implemented their own.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented May 13, 2024

Copy link
Copy Markdown
Contributor Author

IDK, it was a weekend fun PR, this one, so, I didn't verified yet :P

In case, I should send this PR elsewhere?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented May 13, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

The interesting bit, as proposed by @jasonk000 in a different chat (informal and nerdy), is that this same approach could be reused on utf8 decoding too, although it needs special handling of the Latin case (single byte)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bonzini
bonzini reviewed May 13, 2024
View reviewed changes
Comment thread codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32FrameDecoder.java Outdated
// this is not brilliant, we have a data dependency here
int wholeWithContinuations = (wholeOrMore << shiftToHighlightTheWhole) >> shiftToHighlightTheWhole;
// mix them up as per varint spec while dropping the continuation bits
int result = wholeWithContinuations & 0x7F |

@bonzini bonzini May 13, 2024

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done in two steps instead of four.

wwc = (wwc & 0x7F007F) | ((wwc & 0x7F007F00) >> 1);
wwc = (wwc & 0x3FFF) | ((wwc & 0x3FFF0000) >> 2);

Probably no difference, just for the kicks.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

franz1981 reacted with heart emoji
All reactions
  • ❤️ 1 reaction

@franz1981 franz1981 May 13, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a "small" but real improvement, worthy to use this, IMO, many thanks!

Let me know if the tons of comments make sense!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@SirYwell SirYwell May 13, 2024

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory this would also be a fit for the PEXT instruction exposed via Integer.compress since Java 19. But even when using Java 19+, that's risky because e.g. Zen 2 doesn't have proper hardware for that instruction, and other architectures fall back to a more expensive implementation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@franz1981 franz1981 May 13, 2024

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very nice, actually - let me check on the JDK main

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@franz1981
Added the bonzini version
1e1a66a
@franz1981

franz1981 commented May 13, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

These are the changes after @bonzini smart suggestion!

Benchmark                                (inputDistribution)  (inputs)  Mode  Cnt  Score   Error  Units
VarintDecodingBenchmark.readRawVarint32                SMALL         1  avgt   10  1.507 ± 0.009  ns/op
VarintDecodingBenchmark.readRawVarint32                SMALL       128  avgt   10  2.268 ± 0.019  ns/op
VarintDecodingBenchmark.readRawVarint32                SMALL    128000  avgt   10  6.259 ± 0.056  ns/op
VarintDecodingBenchmark.readRawVarint32                LARGE         1  avgt   10  3.055 ± 0.022  ns/op
VarintDecodingBenchmark.readRawVarint32               MEDIUM         1  avgt   10  3.094 ± 0.033  ns/op
VarintDecodingBenchmark.readRawVarint32               MEDIUM       128  avgt   10  3.090 ± 0.021  ns/op
VarintDecodingBenchmark.readRawVarint32               MEDIUM    128000  avgt   10  3.066 ± 0.019  ns/op
VarintDecodingBenchmark.readRawVarint32                  ALL         1  avgt   10  3.010 ± 0.021  ns/op
VarintDecodingBenchmark.readRawVarint32                  ALL       128  avgt   10  3.480 ± 0.025  ns/op
VarintDecodingBenchmark.readRawVarint32                  ALL    128000  avgt   10  8.041 ± 0.085  ns/op

which shows a relevant improvement, instead; it is likely that although I relied on not have dependency between the 4 bytes masks (between each others), I've introduced dep on how to obtain a clean version (the absolute value) of each, while this version won't do it (the IPC is now approaching 4.9/5 on my Ryzen, while it was at 4.7), well done!

lucamolteni reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981
franz1981 marked this pull request as ready for review May 13, 2024 11:09
@franz1981

franz1981 commented May 13, 2024

Copy link
Copy Markdown
Contributor Author

would be great if any Apple users could give it a shot

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bonzini

bonzini commented May 13, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Ah, the same bit packing trick can also be applied to readRawVarint40.

Also, I think this:

        int shiftToHighlightTheWhole = 32 - bitsToKeep;
        // this is not brilliant, we have a data dependency here
        int wholeWithContinuations = (wholeOrMore << shiftToHighlightTheWhole) >> shiftToHighlightTheWhole;

can indeed be written with a lot fewer data dependencies:

    int thisVarintMask = firstOneOnStop ^ (firstOneOnStop - 1);
    int wholeWithContinuations = wholeOrMore & thisVarintMask;

The idea is that thisVarintMask has 0s above the first one of firstOneOnStop, and 1s at and below it. For example if firstOneOnStop is 0x800080 (where the last 0x80 is the only one that matters), then thisVarintMask is 0xFF.

On x86, computing thisVarintMask is even a single BLSMSK instruction! (And indeed my train of thought started with "there must be a BMI instruction for that and maybe you can write it in Java")

franz1981 reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented May 13, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Thanks @bonzini I didn't knew of the BLSMSK instruction (!!!): I had this previous comment before d029cb3#diff-1550582c1bcfe50538698be3c39964078cca007dc5acb1503d54416a659a80faR86-R91

which should be similar (because I still need the bitsToKeep) - but I have to double check the asm produced...
I didn't measured any improvement at that time, worth give it a shot again!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bonzini

bonzini commented May 13, 2024

Copy link
Copy Markdown

but I didn't measured any improvement at that time, worth give it a shot again!

Another possibility is this small optimization on 32-x.

        int bitsToStop = Integer.numberOfTrailingZeros(firstOneOnStop);
        buffer.skipBytes((bitsToStop + 1) >> 3);
        /* x <= 24, so: 32 - (x + 1) = 31 - x = x ^ 31 */
        int shiftToHighlightTheWhole = bitsToStop ^ 31;
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981

franz1981 commented May 13, 2024

Copy link
Copy Markdown
Contributor Author

And @bonzini was very right, this new version is further improving perf a bit:

Benchmark                                (inputDistribution)  (inputs)  Mode  Cnt  Score   Error  Units
VarintDecodingBenchmark.readRawVarint32               MEDIUM         1  avgt   10  2.938 ± 0.036  ns/op
VarintDecodingBenchmark.readRawVarint32               MEDIUM       128  avgt   10  2.975 ± 0.024  ns/op
VarintDecodingBenchmark.readRawVarint32               MEDIUM    128000  avgt   10  2.973 ± 0.039  ns/op

making this very similar in perf than the original method, for predictable inputs as well

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981
Added the bonzini version
d44c410
@franz1981

franz1981 commented May 13, 2024

Copy link
Copy Markdown
Contributor Author

Another possibility is this small optimization on 32-x.

this one doesn't seem to improve (the opposite), but as usual: my Ryzen story, I have to read the ASM first, but thanks for #14050 (comment): my previous branch at d029cb3#diff-1550582c1bcfe50538698be3c39964078cca007dc5acb1503d54416a659a80faR86-R91 was broken, because I didn't used the ^ to null out the garbage left to the important bits

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

chrisvest
chrisvest approved these changes May 14, 2024
View reviewed changes
@chrisvest
chrisvest merged commit 7ad2b91 into netty:4.1 May 14, 2024
chrisvest pushed a commit that referenced this pull request May 14, 2024
@franz1981 @chrisvest
Branchless varint decoding (#14050)
09b4ea6
Motivation:

varint decoding fall shortly when input length is not predictable

Modification:

Implements branchless and batchy varint decoding

Result:

Better performance when inputs length is not predictable
@chrisvest

chrisvest commented May 14, 2024

Copy link
Copy Markdown
Member

Thanks, @franz1981 !

franz1981 reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franz1981
franz1981 deleted the 4.1_branchless_varint branch June 2, 2024 19:59
@normanmaurer normanmaurer mentioned this pull request Sep 14, 2026
Http2: Reserve promised stream for PUSH_PROMISE after local RST_STREAM #17471
Closed
This was referenced Sep 20, 2026
ProtobufVarint32FrameDecoder desynchronizes the stream when a 4-byte length prefix is split after 3 bytes #17549
Closed
ProtobufVarint32FrameDecoder must wait for more data when the length prefix is incomplete #17550
Merged
normanmaurer pushed a commit that referenced this pull request Sep 20, 2026
@ohchanKyu
ProtobufVarint32FrameDecoder must wait for more data when the length …
335aed7
…prefix is incomplete (#17550)

Motivation:

Since #14050 two incomplete length prefix cases are no longer treated as
"need more data" by `ProtobufVarint32FrameDecoder`:

- If only 3 bytes are readable and all of them have the continuation bit
set, `readRawVarint24` returned the partial value and left the
readerIndex advanced. `decode()` then used the low 21 bits of the real
length. When these bits are 0, i.e. the message length is an exact
multiple of 2 MiB, an empty frame was emitted, the prefix bytes were
consumed and the rest of the stream was decoded from the wrong position.
A single 2 MiB message split after the third prefix byte was delivered
as about 2 million bogus frames without any exception.
- If exactly 4 bytes are readable and all of them have the continuation
bit set, `readRawVarint40` threw a `CorruptedFrameException` although
the fifth byte may simply not have been received yet.

Before #14050 both cases reset the readerIndex and returned 0.

Modifications:

- `readRawVarint24` resets the readerIndex and returns 0 when the third
byte still has the continuation bit set.
- `readRawVarint40` returns 0 without moving the readerIndex when only 4
bytes are readable, and only throws when the fifth byte is malformed.
- Add tests that split 1 to 5 byte length prefixes at every position,
including lengths that are exact multiples of 2 MiB.

Result:

`ProtobufVarint32FrameDecoder` produces the same frames 
regardless of how the length prefix is fragmented across reads.

Fixes #17549.
This was referenced Sep 20, 2026
Auto-port 4.1: ProtobufVarint32FrameDecoder must wait for more data when the length prefix is incomplete #17553
Merged
Auto-port 5.0: ProtobufVarint32FrameDecoder must wait for more data when the length prefix is incomplete #17554
Merged
normanmaurer added a commit that referenced this pull request Sep 20, 2026
@netty-project-bot @ohchanKyu @normanmaurer
Auto-port 4.1: ProtobufVarint32FrameDecoder must wait for more data w…
7375bc7
…hen the length prefix is incomplete (#17553)

Auto-port of #17550 to 4.1
Cherry-picked commit: 335aed7

---
Motivation:

Since #14050 two incomplete length prefix cases are no longer treated as
"need more data" by `ProtobufVarint32FrameDecoder`:

- If only 3 bytes are readable and all of them have the continuation bit
set, `readRawVarint24` returned the partial value and left the
readerIndex advanced. `decode()` then used the low 21 bits of the real
length. When these bits are 0, i.e. the message length is an exact
multiple of 2 MiB, an empty frame was emitted, the prefix bytes were
consumed and the rest of the stream was decoded from the wrong position.
A single 2 MiB message split after the third prefix byte was delivered
as about 2 million bogus frames without any exception.
- If exactly 4 bytes are readable and all of them have the continuation
bit set, `readRawVarint40` threw a `CorruptedFrameException` although
the fifth byte may simply not have been received yet.

Before #14050 both cases reset the readerIndex and returned 0.

Modifications:

- `readRawVarint24` resets the readerIndex and returns 0 when the third
byte still has the continuation bit set.
- `readRawVarint40` returns 0 without moving the readerIndex when only 4
bytes are readable, and only throws when the fifth byte is malformed.
- Add tests that split 1 to 5 byte length prefixes at every position,
including lengths that are exact multiples of 2 MiB.

Result:

`ProtobufVarint32FrameDecoder` produces the same frames 
regardless of how the length prefix is fragmented across reads.

Fixes #17549.

---------

Co-authored-by: 오규찬 (B팀 서버) <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
normanmaurer added a commit that referenced this pull request Sep 20, 2026
@netty-project-bot @ohchanKyu @normanmaurer
Auto-port 5.0: ProtobufVarint32FrameDecoder must wait for more data w…
0c32a23
…hen the length prefix is incomplete (#17554)

Auto-port of #17550 to 5.0
Cherry-picked commit: 335aed7

---
Motivation:

Since #14050 two incomplete length prefix cases are no longer treated as
"need more data" by `ProtobufVarint32FrameDecoder`:

- If only 3 bytes are readable and all of them have the continuation bit
set, `readRawVarint24` returned the partial value and left the
readerIndex advanced. `decode()` then used the low 21 bits of the real
length. When these bits are 0, i.e. the message length is an exact
multiple of 2 MiB, an empty frame was emitted, the prefix bytes were
consumed and the rest of the stream was decoded from the wrong position.
A single 2 MiB message split after the third prefix byte was delivered
as about 2 million bogus frames without any exception.
- If exactly 4 bytes are readable and all of them have the continuation
bit set, `readRawVarint40` threw a `CorruptedFrameException` although
the fifth byte may simply not have been received yet.

Before #14050 both cases reset the readerIndex and returned 0.

Modifications:

- `readRawVarint24` resets the readerIndex and returns 0 when the third
byte still has the continuation bit set.
- `readRawVarint40` returns 0 without moving the readerIndex when only 4
bytes are readable, and only throws when the fifth byte is malformed.
- Add tests that split 1 to 5 byte length prefixes at every position,
including lengths that are exact multiples of 2 MiB.

Result:

`ProtobufVarint32FrameDecoder` produces the same frames 
regardless of how the length prefix is fragmented across reads.

Fixes #17549.

---------

Co-authored-by: 오규찬 (B팀 서버) <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
@normanmaurer normanmaurer mentioned this pull request Sep 21, 2026
cache failure 1233e4a5 #17565
Closed
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@netty-project-bot @ohchanKyu
@normanmaurer @lltopk
Auto-port 4.1: ProtobufVarint32FrameDecoder must wait for more data w…
5d76ebf
…hen the length prefix is incomplete (netty#17553)

Auto-port of netty#17550 to 4.1
Cherry-picked commit: 335aed7

---
Motivation:

Since netty#14050 two incomplete length prefix cases are no longer treated as
"need more data" by `ProtobufVarint32FrameDecoder`:

- If only 3 bytes are readable and all of them have the continuation bit
set, `readRawVarint24` returned the partial value and left the
readerIndex advanced. `decode()` then used the low 21 bits of the real
length. When these bits are 0, i.e. the message length is an exact
multiple of 2 MiB, an empty frame was emitted, the prefix bytes were
consumed and the rest of the stream was decoded from the wrong position.
A single 2 MiB message split after the third prefix byte was delivered
as about 2 million bogus frames without any exception.
- If exactly 4 bytes are readable and all of them have the continuation
bit set, `readRawVarint40` threw a `CorruptedFrameException` although
the fifth byte may simply not have been received yet.

Before netty#14050 both cases reset the readerIndex and returned 0.

Modifications:

- `readRawVarint24` resets the readerIndex and returns 0 when the third
byte still has the continuation bit set.
- `readRawVarint40` returns 0 without moving the readerIndex when only 4
bytes are readable, and only throws when the fifth byte is malformed.
- Add tests that split 1 to 5 byte length prefixes at every position,
including lengths that are exact multiples of 2 MiB.

Result:

`ProtobufVarint32FrameDecoder` produces the same frames 
regardless of how the length prefix is fragmented across reads.

Fixes netty#17549.

---------

Co-authored-by: 오규찬 (B팀 서버) <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@chrisvest chrisvest chrisvest approved these changes
+2 more reviewers
@bonzini bonzini bonzini left review comments
@SirYwell SirYwell SirYwell left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@franz1981 @chrisvest @bonzini @SirYwell
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.