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

Increase the smallvec length for Bitfield #35

Closed
wants to merge 4 commits into from

Conversation

paulhauner
Copy link
Member

@paulhauner paulhauner commented Nov 25, 2024

Increases the size of the Bitfield on the stack to 80 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 ~1.31M 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?

Let's look at byte sizes that are a multiple of 8 (64 bits, 1 word). We will assume that the number of validators supported by a given bitfield size is N * 32 slots * 64 committees * 8 bits.

  • 64 bytes = 1,048,576 validators
  • 72 bytes = 1,179,648 validators
  • 80 bytes = 1,310,720 validators

At the time of writing, Ethereum has 1,071,080 active validators. 80 bytes seems to be a small enough number that gives us some headroom.

Copy link

codecov bot commented Nov 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.16%. Comparing base (9e59ff9) to head (2671609).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #35   +/-   ##
=======================================
  Coverage   61.16%   61.16%           
=======================================
  Files           9        9           
  Lines         497      497           
=======================================
  Hits          304      304           
  Misses        193      193           

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

@paulhauner paulhauner marked this pull request as ready for review December 4, 2024 21:18
@paulhauner
Copy link
Member Author

This one is ready for review ☺️ Maybe @michaelsproul would be a good one for this?

@michaelsproul
Copy link
Member

On it!

@michaelsproul
Copy link
Member

Thoughts on going even higher to e.g. 128 bytes?

This would allow us to support Holesky without heap allocations (1.76M validators ~= 107 bytes minimum).

@paulhauner
Copy link
Member Author

Thoughts on going even higher to e.g. 128 bytes?

Yeah, I think that's a good idea indeed. Bumped to 128 bytes. That gives us ~2M validators which is a reasonable target IMO.

@paulhauner
Copy link
Member Author

Oh, looks like I need to do this on ethereum_ssz due to #28. I'll go raise this there.

@paulhauner
Copy link
Member Author

Replaced by sigp/ethereum_ssz#38

@paulhauner paulhauner closed this 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