ssz
ssz copied to clipboard
Add ByteVectorShared - optimize validator object memory
NodeJS represents Uint8Arrays inefficiently when they have small sizes. The validators object have pubkey and withdrawal_credentials that can be thought as an append-only list which take ~140MB in a single state.
An optimization to reduce their memory cost is to keep them in bigger Uint8Arrays that are shared for multiple pubkeys. This is possible as quickly tested in https://github.com/ChainSafe/ssz/tree/dapplion/byteVectorImmutable
Since validator objects are already represented as values internally inside a node the validator object could be a custom class instance with getters for pubkey and withdrawal_credentials that slice a Uint8Array of the shared one.