Skip to content

Speed up compute_ptc#5044

Merged
jtraglia merged 4 commits intoethereum:masterfrom
jtraglia:compute-ptc-speedup
Mar 26, 2026
Merged

Speed up compute_ptc#5044
jtraglia merged 4 commits intoethereum:masterfrom
jtraglia:compute-ptc-speedup

Conversation

@jtraglia
Copy link
Copy Markdown
Member

With #4979 merged, the testing framework generates an input state for each test and calls initialize_ptc_window. This is computing two epochs worth of PTCs which is causing the mainnet tests to take considerably longer; ~5 hours before the change and 12+ hours after the change. On my system, it takes ~30 seconds to compute PTCs for a single epoch. This PR's goal is to speed this up. For details on each optimization, please refer to the extended description for each commit.

Note: This PR is necessary to make the upcoming release. We triggered the release action yesterday but it timed out (12 hours per fork/preset combo) in the Gloas/Heze tests.

image

Move validator balance lookups out of the rejection sampling loop in
`compute_balance_weighted_selection` into a one-time pre-fetch. This avoids
repeated SSZ Merkle tree traversals during each acceptance check, reducing
`compute_ptc` time on mainnet from ~30s to ~9s per epoch (3.3x improvement).

The signature of `compute_balance_weighted_acceptance` changes from
`(state, index, seed, i)` to `(effective_balance, seed, i)`.
@github-actions github-actions bot added testing CI, actions, tests, testing infra gloas labels Mar 26, 2026
Cache three functions that call compute_balance_weighted_selection, which
performs costly SSZ tree traversals for validator balances during rejection
sampling:

- altair: get_next_sync_committee_indices (called at sync committee boundaries)
- fulu: compute_proposer_indices (called during process_proposer_lookahead)
- gloas: compute_ptc (called during process_ptc_window)
@jtraglia jtraglia merged commit 2e55491 into ethereum:master Mar 26, 2026
16 checks passed
@jtraglia jtraglia deleted the compute-ptc-speedup branch March 26, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gloas testing CI, actions, tests, testing infra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant