perf: unroll VarInt parsing loops#826
Open
anthony-swirldslabs wants to merge 9 commits into
Open
Conversation
Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
JUnit Test Report 521 files ±0 521 suites ±0 27s ⏱️ -8s Results for commit d6156cf. ± Comparison against base commit 4201101. This pull request removes 6 and adds 6 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
Integration Test Report 426 files + 3 426 suites +3 24m 58s ⏱️ + 9m 11s Results for commit d6156cf. ± Comparison against base commit 4201101. This pull request removes 2 and adds 16 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
artemananiev
approved these changes
May 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description:
Updating the varint parsing implementation by:
int, and then switching to alongaccumulator to reduce the cost of bitwise operations-1bytes and interprets them as a varint with value-1, even though this is a malformed representation that must throw an exception.A unit test is added to verify the correctness of the new algorithm. All the PBJ implementations are updated: ReadableSequentialData , DirectBufferedData, RandomAccessData, ByteArrayBufferedData, and Bytes. The benchmark is updated as well.
Performance testing:
The benchmark was run on a real Linux AMD hardware: https://github.com/hashgraph/pbj/actions/runs/25944398410/job/76269270691
The current PBJ implementation appears to be slower than Google. Please note that previously, this wasn't the case on Linux AMD, as can be seen at #797 (comment) . I'm unsure what caused the discrepancy, but Google implementation is currently consistently faster than the current PBJ implementation. Our new implementation introduced in this fix is even superior to Google:
The performance improvements are reproducible consistently after multiple re-runs (can be seen at https://github.com/hashgraph/pbj/actions/workflows/performance-PBJ-JMH.yml ).
Related issue(s):
Fixes #798
Notes for reviewer:
All tests should pass.
Checklist