lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

Replace HashSet with BitVector for permanent attestation subscriptions

Open VolodymyrBg opened this issue 7 months ago • 15 comments

Issue Addressed

This PR addresses issue #XXX: Optimizing memory usage and performance of the subnet service.

Proposed Changes

  • Replaces HashSet<Subnet> with BitVector for storing permanent attestation subscriptions
  • Updates related methods to work with bit operations instead of HashSet operations
  • Modifies the subscription checks to handle the new BitVector implementation
  • Updates test methods to work properly with the new data structure

Additional Info

This change improves both memory efficiency and performance of the subnet service. BitVector is a more space-efficient representation for tracking subnet subscriptions, which is particularly important for nodes with many validators or high network activity. The implementation follows a pattern already used elsewhere in the codebase for subnet bitfields, specifically in ENR attestation and sync committee bitfields, creating a more consistent approach to subnet tracking throughout the codebase.

VolodymyrBg avatar Apr 11 '25 15:04 VolodymyrBg

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 11 '25 15:04 CLAassistant

Hey @VolodymyrBg ! While this may reduce memory, I think the reduction is negligible. LH average memory is on the order of GBs and there are at most 64 subnets

dapplion avatar Apr 11 '25 21:04 dapplion

Thanks for the PR! I'm generally in agreement with @dapplion here but I also see that this was addressing a TODO so we should give it some consideration and at the very least remove the TODO if we don't think these changes are worth it.

For now I've just left a comment about the usage of expect

I've made some corrections, but if this change is not necessary I can close it.

VolodymyrBg avatar Apr 12 '25 14:04 VolodymyrBg

Could you please sign the CLA? Thanks

I see that the PR is currently targeting the stable branch, can you change it to unstable?

chong-he avatar Apr 14 '25 05:04 chong-he

This pull request has merge conflicts. Could you please resolve them @VolodymyrBg? 🙏

mergify[bot] avatar Apr 14 '25 10:04 mergify[bot]

I've gone ahead and set the target branch to unstable for you. However, now your PR includes some commits from stable which we don't actually want in unstable. Can you do an interactive rebase (git rebase -i unstable) and remove any commits that you didn't author? Thanks

Thanks, i'll try

VolodymyrBg avatar Apr 14 '25 11:04 VolodymyrBg

I've gone ahead and set the target branch to unstable for you. However, now your PR includes some commits from stable which we don't actually want in unstable. Can you do an interactive rebase (git rebase -i unstable) and remove any commits that you didn't author? Thanks

Done

VolodymyrBg avatar Apr 14 '25 14:04 VolodymyrBg

I vote to remove the TODO unless someone else justifies otherwise

@AgeManning Blame points to you as author https://github.com/sigp/lighthouse/commit/08e8b92e5032044f253a7357aaf0a7c74f9f8b80#diff-e3499b786075371d4d8f0407ea9795dce66efca341265c55b1a225aa6d9ce09fR92

dapplion avatar Apr 23 '25 15:04 dapplion

Oh yeah. I wrote that todo as I was implementing this change and had considered a bitvector for initial implementation but later decided it wasn't worth the effort (as I'd have to implement the dynamic bitvector).

I believe @jking-aus has made a dynamic bit vector and we probably should use that to remove the EthSpec dep.

I'll be able to properly review this next week, but I'm fine for going either way with this.

AgeManning avatar Apr 24 '25 22:04 AgeManning

@mergifyio queue

AgeManning avatar May 12 '25 01:05 AgeManning

queue

🛑 The pull request has been synchronized by a user

mergify[bot] avatar May 12 '25 01:05 mergify[bot]

Looks like you need to solve clippy lints and run cargo fmt. To solve clippy lints, run make lint from the lighthouse directory and correct the errors.

AgeManning avatar May 12 '25 01:05 AgeManning

This pull request has been removed from the queue for the following reason: pull request manually updated.

The pull request #7317 has been manually updated.

If you want to requeue this pull request, you can post a @mergifyio requeue comment.

mergify[bot] avatar May 12 '25 01:05 mergify[bot]

@AgeManning Fixed clippy

VolodymyrBg avatar May 12 '25 17:05 VolodymyrBg

@AgeManning

VolodymyrBg avatar Jun 11 '25 15:06 VolodymyrBg

I vote to remove the TODO unless someone else justifies otherwise

@AgeManning Blame points to you as author 08e8b92#diff-e3499b786075371d4d8f0407ea9795dce66efca341265c55b1a225aa6d9ce09fR92

+1 I'm also not sure if it's worth the change, changing HashSet<Subnet> to a BitVector with only 64 elements doesn't seem to give us much. Not strongly opposed to it though.

jimmygchen avatar Jun 27 '25 13:06 jimmygchen

I vote to remove the TODO unless someone else justifies otherwise @AgeManning Blame points to you as author 08e8b92#diff-e3499b786075371d4d8f0407ea9795dce66efca341265c55b1a225aa6d9ce09fR92

+1 I'm also not sure if it's worth the change, changing HashSet<Subnet> to a BitVector with only 64 elements doesn't seem to give us much. Not strongly opposed to it though.

So, what to do? Should I make corrections to the code, or is it useless?

VolodymyrBg avatar Jun 27 '25 18:06 VolodymyrBg

If we don't want to add the complexity (others vote to avoid it), then I think this PR is still useful for fixing the waker and maybe removing the original comment.

AgeManning avatar Jun 29 '25 23:06 AgeManning

Hi @VolodymyrBg, this pull request has been closed automatically due to 30 days of inactivity. If you’d like to continue working on it, feel free to reopen at any time.

mergify[bot] avatar Jul 29 '25 23:07 mergify[bot]