chore: use treeview getAll in inactivity_scores#193
Conversation
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Summary of ChangesHello @GrapeBaBa, 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 refactors the 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. 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 performance improvement in processInactivityUpdates by fetching all inactivity_scores in a single getAll call, rather than individually within a loop. This is a good optimization that follows existing patterns in the codebase. The implementation is correct, including the necessary memory management. I have one minor style suggestion to align with the repository's style guide for resource allocation.
| const inactivity_scores_values = try inactivity_scores.getAll(allocator); | ||
| defer allocator.free(inactivity_scores_values); |
There was a problem hiding this comment.
To improve readability and make resource management clearer, the repository style guide recommends visually separating resource allocation and deallocation blocks with newlines.
const inactivity_scores_values = try inactivity_scores.getAll(allocator);
defer allocator.free(inactivity_scores_values);
References
- The style guide recommends using newlines around resource allocation and deallocation blocks to improve readability and help identify potential leaks. (link)
|
lgtm |
5a7c541 to
79d4e1b
Compare
There was a problem hiding this comment.
Pull request overview
This PR optimizes processInactivityUpdates by reducing per-validator TreeView reads through a bulk load of inactivity scores, aligning with the TODO optimization and Lodestar’s approach.
Changes:
- Bulk-load inactivity scores via
TreeView.getAll()instead of callingget(i)per validator. - Commit the inactivity scores view before bulk reading to satisfy TreeView bulk-read constraints.
- Add a length assertion between
flagsand the bulk-loaded inactivity scores slice.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const allocator = state.baseView().allocator; | ||
| const inactivity_scores_values = try inactivity_scores.getAll(allocator); | ||
| defer allocator.free(inactivity_scores_values); |
There was a problem hiding this comment.
getAll() allocates a full inactivity_scores_values slice, but it uses state.baseView().allocator (tied to the state’s lifetime) rather than the epoch-transition scratch allocator already available in processEpoch. This can increase long-lived heap pressure and makes it harder to switch epoch processing to an arena/scratch allocator. Consider threading an allocator: std.mem.Allocator parameter into processInactivityUpdates (like other epoch processing fns) and using that for the bulk read buffer instead of the state’s allocator.
There was a problem hiding this comment.
@GrapeBaBa yes this should be done. Eg: add allocator as param to processInactivityUpdates
| std.debug.assert(flags.len <= inactivity_scores_values.len); | ||
| for (0..flags.len) |i| { | ||
| const flag = flags[i]; | ||
| if (hasMarkers(flag, FLAG_ELIGIBLE_ATTESTER)) { | ||
| var inactivity_score = try inactivity_scores.get(i); | ||
| var inactivity_score = inactivity_scores_values[i]; |
There was a problem hiding this comment.
std.debug.assert(flags.len <= inactivity_scores_values.len) is compiled out in release builds; if these lengths ever diverge, the loop will index out of bounds when reading inactivity_scores_values[i]. Prefer a runtime guard (e.g., return an error) before the loop. Since inactivity_scores is expected to track validator count, also consider checking for equality rather than just <=.
Signed-off-by: Chen Kai <281165273grape@gmail.com>
79d4e1b to
31bf8b3
Compare
**Motivation** Reduce per-validator TreeView reads in `processInactivityUpdates` by bulk-loading inactivity scores, matching the intended TODO optimization and Lodestar’s approach. Fix #194 --------- Signed-off-by: Chen Kai <281165273grape@gmail.com> Co-authored-by: Cayman <caymannava@gmail.com>
Motivation
Reduce per-validator TreeView reads in
processInactivityUpdatesby bulk-loading inactivity scores, matching the intended TODO optimization and Lodestar’s approach.Fix #194