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

More efficient implementation of the 'POST beacon_committee_subscriptions' API #3153

Merged
merged 3 commits into from
Dec 3, 2021

Conversation

zah
Copy link
Contributor

@zah zah commented Dec 2, 2021

No description provided.

@@ -503,30 +503,38 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
if not(node.isSynced(node.dag.head)):
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)

let
wallSlot = node.beaconClock.now.slotOrZero
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Variables were hoisted outside of the loop.

for duty in tracker.duties.mitems():
if duty == newDuty:
return
if newDuty in tracker.duties:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quadratic complexity was eliminated through switching to a HashSet.

Copy link
Member

Choose a reason for hiding this comment

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

the hashset is certainly an improvement - fwiw, there exists an alternative implementation that @tersec was employing before, that was lost in refactoring: instead of storing each duty in a collection one can assign the bit field of subnets to listen to with an or operation, so that each duty sets bits for the slot within the epoch and those before - it makes for some ugly code but turns the new duty assignment into a constant operation with bounded memory - in hindsight it probably would have made sense to port that implementation to here.

@github-actions
Copy link

github-actions bot commented Dec 2, 2021

Unit Test Results

     12 files  ±0     756 suites  ±0   37m 24s ⏱️ -38s
1 527 tests ±0  1 481 ✔️ ±0  46 💤 ±0  0 ±0 
9 056 runs  ±0  8 960 ✔️ ±0  96 💤 ±0  0 ±0 

Results for commit e5fc6e5. ± Comparison against base commit 5e9625c.

♻️ This comment has been updated with latest results.

@zah zah merged commit 74c63ed into unstable Dec 3, 2021
@zah zah deleted the fast_beacon_committee_subscriptions branch December 3, 2021 15:04
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