Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Bitfield smallvec to 128 to avoid heap allocations #38

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

paulhauner
Copy link
Member

Increases the size of the Bitfield on the stack to 128 bytes. If the smallvec exceeds this then it will allocate to the heap.

This has the effect of ensuring that the Attestation bitfield can live on the stack for all networks with up to ~2M validators.

Allocating the Attestation to the heap is slow and increase memory fragmentation. This affects attestation deserialisation (happens very frequently) and block deserialisation (happens less frequently, but is latency critical).

Why 80 bytes?

The number of validators supported by a given bitfield size is N * 32 slots * 64 committees * 8 bits.

At the time of writing, mainnet has ~1.1M active validators and Holesky has ~1.76M.

128 is a nice round multiple of 8 that fits Holesky without putting too much on the stack.

Notes

This PR originally appeared at sigp/ssz_types#35

@paulhauner paulhauner added invalid This doesn't seem right and removed invalid This doesn't seem right labels Dec 5, 2024
@paulhauner paulhauner changed the title Bump smallvec len to 128 Bump Bitfield smallvec to 128 to avoid heap allocations Dec 5, 2024
Copy link

codecov bot commented Dec 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.50%. Comparing base (d1acd77) to head (b92a494).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #38   +/-   ##
=======================================
  Coverage   77.50%   77.50%           
=======================================
  Files          12       12           
  Lines         720      720           
=======================================
  Hits          558      558           
  Misses        162      162           

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

Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

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

Nice

@michaelsproul michaelsproul merged commit ed1405b into main Dec 5, 2024
7 checks passed
@michaelsproul michaelsproul deleted the bump-smallvec-len branch December 5, 2024 00:30
@michaelsproul michaelsproul mentioned this pull request Dec 5, 2024
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