Skip to content

Conversation

@michaelsproul
Copy link
Member

@michaelsproul michaelsproul commented Sep 3, 2025

This PR optimises integer decoding by inlining the decoding functions aggressively.

The speedup is around 60% for u8 per benchmarks from this PR:

decode_fixed_vector/u8_128k
                        time:   [118.56 µs 119.22 µs 119.99 µs]
                        change: [−61.759% −61.667% −61.573%] (p = 0.00 < 0.05)
                        Performance has improved.

Inlining is the main source of gains, the "simpler" FastU8 impl from the ssz_types PR actually turns out to be 3% slower than just inlining the current impl.

TODO:

  • Confirm performance benefit for other uint types.

@codecov
Copy link

codecov bot commented Sep 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.16%. Comparing base (5b6dd17) to head (2afb83d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #55      +/-   ##
==========================================
+ Coverage   75.59%   76.16%   +0.56%     
==========================================
  Files          13       13              
  Lines         795      797       +2     
==========================================
+ Hits          601      607       +6     
+ Misses        194      190       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@jimmygchen jimmygchen left a comment

Choose a reason for hiding this comment

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

Great find 🎉

@michaelsproul
Copy link
Member Author

The benchmarks for u64 lists are also greatly improved by these changes:

fixed_vector/decode_u64_128k
                        time:   [72.013 µs 72.038 µs 72.066 µs]
                        change: [−63.833% −63.646% −63.454%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 11 outliers among 100 measurements (11.00%)
  4 (4.00%) high mild
  7 (7.00%) high severe

fixed_vector/encode_u64_128k
                        time:   [67.006 µs 67.145 µs 67.299 µs]
                        change: [−70.382% −70.308% −70.223%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 9 outliers among 100 measurements (9.00%)
  8 (8.00%) high mild
  1 (1.00%) high severe

variable_list/decode_u64_128k
                        time:   [71.978 µs 72.135 µs 72.257 µs]
                        change: [−57.648% −57.407% −57.177%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 12 outliers among 100 measurements (12.00%)
  6 (6.00%) low severe
  5 (5.00%) low mild
  1 (1.00%) high mild

variable_list/encode_u64_128k
                        time:   [82.348 µs 82.562 µs 82.832 µs]
                        change: [−56.293% −55.142% −53.937%] (p = 0.00 < 0.05)
                        Performance has improved.

@michaelsproul michaelsproul merged commit 7aec9c0 into main Sep 4, 2025
8 checks passed
@michaelsproul michaelsproul deleted the faster-uint branch September 4, 2025 06:14
macladson pushed a commit that referenced this pull request Sep 30, 2025
* Faster uint decoding

* Inline encoding as well
@macladson macladson mentioned this pull request Sep 30, 2025
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.

2 participants