Skip to content

chore: use treeview getAll in inactivity_scores#193

Merged
wemeetagain merged 22 commits intomainfrom
gr/inactivity_op
Feb 2, 2026
Merged

chore: use treeview getAll in inactivity_scores#193
wemeetagain merged 22 commits intomainfrom
gr/inactivity_op

Conversation

@GrapeBaBa
Copy link
Copy Markdown
Contributor

@GrapeBaBa GrapeBaBa commented Jan 27, 2026

Motivation

Reduce per-validator TreeView reads in processInactivityUpdates by bulk-loading inactivity scores, matching the intended TODO optimization and Lodestar’s approach.

Fix #194

wemeetagain and others added 19 commits January 19, 2026 19:00
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>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 processInactivityUpdates function to optimize how inactivity scores are accessed. By fetching all scores into a local array at once rather than querying them individually, the change aims to improve efficiency and streamline data handling. It also incorporates explicit memory management for the temporary data structure, ensuring resources are properly released.

Highlights

  • Refactored Inactivity Score Retrieval: The method for accessing inactivity scores has been updated from individual get(i) calls within a loop to a single getAll(allocator) call, retrieving all scores into a local array. This change likely improves performance by reducing repeated data access operations.
  • Enhanced Memory Management: Explicit memory allocation and deallocation for the temporary inactivity_scores_values array have been introduced using defer allocator.free, ensuring proper resource management.
  • Code Cleanup: A TODO comment related to TreeView conversion has been removed, indicating progress or resolution of the noted item.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +36 to +37
const inactivity_scores_values = try inactivity_scores.getAll(allocator);
defer allocator.free(inactivity_scores_values);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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
  1. The style guide recommends using newlines around resource allocation and deallocation blocks to improve readability and help identify potential leaks. (link)

@wemeetagain
Copy link
Copy Markdown
Member

lgtm

@wemeetagain wemeetagain marked this pull request as ready for review January 29, 2026 15:54
@wemeetagain wemeetagain requested a review from a team as a code owner January 29, 2026 15:54
Base automatically changed from comptime-fork to main January 29, 2026 15:55
Copilot AI review requested due to automatic review settings January 29, 2026 16:00
wemeetagain
wemeetagain previously approved these changes Jan 29, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 calling get(i) per validator.
  • Commit the inactivity scores view before bulk reading to satisfy TreeView bulk-read constraints.
  • Add a length assertion between flags and the bulk-loaded inactivity scores slice.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +35 to +37
const allocator = state.baseView().allocator;
const inactivity_scores_values = try inactivity_scores.getAll(allocator);
defer allocator.free(inactivity_scores_values);
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@GrapeBaBa yes this should be done. Eg: add allocator as param to processInactivityUpdates

Comment on lines +38 to +42
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];
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

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 <=.

Copilot uses AI. Check for mistakes.
Signed-off-by: Chen Kai <281165273grape@gmail.com>
@GrapeBaBa GrapeBaBa requested a review from wemeetagain January 30, 2026 14:52
@wemeetagain wemeetagain merged commit eb0ad18 into main Feb 2, 2026
10 checks passed
twoeths pushed a commit that referenced this pull request Mar 3, 2026
**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>
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.

reduce per-validator TreeView reads in processInactivityUpdates by bulk-loading inactivity scores

3 participants