Skip to content

perf: test vectorized varint algo#811

Open
anthony-swirldslabs wants to merge 1 commit intomainfrom
810-vectorVarInt
Open

perf: test vectorized varint algo#811
anthony-swirldslabs wants to merge 1 commit intomainfrom
810-vectorVarInt

Conversation

@anthony-swirldslabs
Copy link
Copy Markdown
Contributor

Description:
Introducing a vectorized LEB128 algo for reading varint values that uses a fully unrolled loop and employs a "negative limit" trick to avoid explicit limit checks. It's 4x times faster for 1-byte varints than our current implementation. It's consistently and equally fast for 2, 3, 4, and 5-byte varints as well: 2.4x faster for 2 byte and 2x-9x faster for longer encodings.

A varint.md is added to describe the algorithm, so that we don't have to repeat the lengthy doc in every implementation. The core PBJ implementations will be replaced in a separate PR in the future.

Also, a unit test is added to verify the correctness of the algorithm.

Benchmark results:

Benchmark                                          (range)   Mode  Cnt      Score    Error   Units
VarIntByteArrayReadBench.loopLess_withLimitChecks        1  thrpt   15   3073.245 ± 31.117  ops/us
VarIntByteArrayReadBench.loopLess_withLimitChecks        2  thrpt   15   1094.762 ±  2.069  ops/us
VarIntByteArrayReadBench.loopLess_withLimitChecks        3  thrpt   15    798.020 ±  2.915  ops/us
VarIntByteArrayReadBench.loopLess_withLimitChecks        4  thrpt   15    583.936 ±  3.379  ops/us
VarIntByteArrayReadBench.loopLess_withLimitChecks        5  thrpt   15    482.653 ±  1.005  ops/us
VarIntByteArrayReadBench.pbj                             1  thrpt   15   3091.400 ± 10.347  ops/us
VarIntByteArrayReadBench.pbj                             2  thrpt   15    956.869 ±  4.053  ops/us
VarIntByteArrayReadBench.pbj                             3  thrpt   15    856.654 ±  1.854  ops/us
VarIntByteArrayReadBench.pbj                             4  thrpt   15    692.485 ±  0.826  ops/us
VarIntByteArrayReadBench.pbj                             5  thrpt   15    261.279 ±  0.344  ops/us
VarIntByteArrayReadBench.vector_zigZag                   1  thrpt   15  12778.304 ± 19.838  ops/us
VarIntByteArrayReadBench.vector_zigZag                   2  thrpt   15   2387.618 ± 29.285  ops/us
VarIntByteArrayReadBench.vector_zigZag                   3  thrpt   15   2023.312 ±  4.401  ops/us
VarIntByteArrayReadBench.vector_zigZag                   4  thrpt   15   2054.741 ± 27.816  ops/us
VarIntByteArrayReadBench.vector_zigZag                   5  thrpt   15   2061.852 ± 21.654  ops/us

Related issue(s):

Fixes #810

Notes for reviewer:
All tests should pass.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
@anthony-swirldslabs anthony-swirldslabs self-assigned this May 1, 2026
@anthony-swirldslabs anthony-swirldslabs requested review from a team as code owners May 1, 2026 23:18
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

JUnit Test Report

    81 files  ±0      81 suites  ±0   3m 16s ⏱️ ±0s
 1 519 tests ±0   1 515 ✅ ±0   4 💤 ±0  0 ❌ ±0 
10 407 runs  ±0  10 379 ✅ ±0  28 💤 ±0  0 ❌ ±0 

Results for commit 8594095. ± Comparison against base commit b629795.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Integration Test Report

    420 files  +1      420 suites  +1   20m 13s ⏱️ - 7m 41s
114 984 tests +2  114 984 ✅ +2  0 💤 ±0  0 ❌ ±0 
115 226 runs  +2  115 226 ✅ +2  0 💤 ±0  0 ❌ ±0 

Results for commit 8594095. ± Comparison against base commit b629795.

This pull request removes 3 and adds 5 tests. Note that renamed tests count towards both.
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [1] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x0000000009b935f0@2a8f10c8
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [2] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x0000000009b93838@61a537ae
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [3] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x0000000009b93a80@376e7549
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [1] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x000000005fc61460@376ef0c9
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [2] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x000000005fc616a8@2c028556
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [3] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x000000005fc618f0@16c48a83
com.hedera.pbj.integration.test.VectorVarIntTest ‑ [1] true
com.hedera.pbj.integration.test.VectorVarIntTest ‑ [2] false

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vectorized varint algo

2 participants