mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 18:32:42 +00:00
Use SmallVec in Bitfield (#3025)
## Issue Addressed Alternative to #2935 ## Proposed Changes Replace the `Vec<u8>` inside `Bitfield` with a `SmallVec<[u8; 32>`. This eliminates heap allocations for attestation bitfields until we reach 500K validators, at which point we can consider increasing `SMALLVEC_LEN` to 40 or 48. While running Lighthouse under `heaptrack` I found that SSZ encoding and decoding of bitfields corresponded to 22% of all allocations by count. I've confirmed that with this change applied those allocations disappear entirely. ## Additional Info We can win another 8 bytes of space by using `smallvec`'s [`union` feature](https://docs.rs/smallvec/1.8.0/smallvec/#union), although I might leave that for a future PR because I don't know how experimental that feature is and whether it uses some spicy `unsafe` blocks.
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1678,6 +1678,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"smallvec",
|
||||
"tree_hash",
|
||||
"tree_hash_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"typenum",
|
||||
@@ -6496,6 +6497,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"serde_yaml",
|
||||
"slog",
|
||||
"smallvec",
|
||||
"state_processing",
|
||||
"superstruct",
|
||||
"swap_or_not_shuffle",
|
||||
|
||||
Reference in New Issue
Block a user