perf(types/electra): model Pending* electra types as ContainerNodeStructType#9054
perf(types/electra): model Pending* electra types as ContainerNodeStructType#9054
Conversation
…ContainerNodeStruct Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a critical performance enhancement for the Electra epoch transition process. By refactoring the underlying data structure for Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant performance improvement by modeling PendingDeposit, PendingPartialWithdrawal, and PendingConsolidation as ContainerNodeStructType instead of ContainerType. The change is well-motivated, and the included benchmark clearly demonstrates the benefits. The implementation is correct. I have one minor suggestion to improve the readability and structure of the new benchmark test file.
| const view = listType.defaultViewDU(); | ||
| const defaultDeposit = ssz.electra.PendingDeposit.defaultValue(); | ||
| for (let i = 0; i < NUM_DEPOSITS; i++) { | ||
| if (listType === ListContainer) { | ||
| view.push(PendingDepositContainer.toViewDU(defaultDeposit)); | ||
| } else { | ||
| view.push(PendingDepositNodeStruct.toViewDU(defaultDeposit)); | ||
| } | ||
| } | ||
| view.commit(); | ||
| return view; |
There was a problem hiding this comment.
The buildList function can be simplified by hoisting the type check out of the loop. Instead of checking listType on every iteration, you can get the elementType from the list type once before the loop. This makes the code cleaner and slightly more performant.
const view = listType.defaultViewDU();
const defaultDeposit = ssz.electra.PendingDeposit.defaultValue();
const itemType = listType.elementType;
for (let i = 0; i < NUM_DEPOSITS; i++) {
view.push(itemType.toViewDU(defaultDeposit));
}
view.commit();
return view;
Performance Report✔️ no performance regression detected Full benchmark results
|
|
the result is under my expectation, it's clear that gc is the main factor for each of the spike
I'd bring this idea to lodestar-z instead ChainSafe/lodestar-z#232 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #9054 +/- ##
=========================================
Coverage 52.32% 52.32%
=========================================
Files 848 848
Lines 62326 62326
Branches 4572 4572
=========================================
Hits 32612 32612
Misses 29649 29649
Partials 65 65 🚀 New features to boost your workflow:
|

Motivation
processPendingDeposits,processPendingConsolidations, and related epoch functions iterate over up to tens of thousands ofPendingDeposit,PendingPartialWithdrawal, andPendingConsolidationitems per epoch transition, reading all fields on each item. These were backed byContainerType, which stores each item as a Merkle tree node — every field read requires tree traversal.ContainerNodeStructTypestores items as plain JS objects (structs), reducing field access to a direct property lookup. A benchmark with 50,000 items and chunked iteration (matching the real access pattern) shows a ~33x speedup: 12.8 ops/s → 417 ops/s.Description
PendingDeposit,PendingPartialWithdrawal, andPendingConsolidationinpackages/types/src/electra/sszTypes.tsasContainerNodeStructTypeinstead ofContainerTypepackages/state-transition/test/perf/epoch/processPendingDeposits.test.tscomparing both types with 50,000 items; benchmark is skipped in CIAI Assistance Disclosure
Used Claude Code to explore the codebase, identify candidates, and write the benchmark.