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

perf(storage): use VecDeque for TableChangeLog to avoid large clone on truncate (#19984) #20003

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Jan 2, 2025

Cherry picking #19984 onto branch release-2.2,

This PR/issue was created by cherry-pick action from commit 5cb0d17.,

Comment on lines +150 to +154
while let Some(change_log) = self.0.front()
&& *change_log.epochs.last().expect("non-empty") <= truncate_epoch
{
let _change_log = self.0.pop_front().expect("non-empty");
}
Copy link

Choose a reason for hiding this comment

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

The while let pattern with && condition can cause a panic since the right side of && will be evaluated even when front() returns None. Here's a safer way to write this:

while let Some(change_log) = self.0.front() {
    if change_log.epochs.last().expect("non-empty") <= &truncate_epoch {
        let _change_log = self.0.pop_front().expect("non-empty");
    } else {
        break;
    }
}

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The while let pattern with && condition can cause a panic since the right side of && will be evaluated even when front() returns None
@wenym1 This seems not true? I tried rust playground and short-circuiting is working with while let

@graphite-app graphite-app bot requested a review from lmatz January 2, 2025 11:01
Copy link

graphite-app bot commented Jan 2, 2025

Graphite Automations

"release branch request review" took an action on this PR • (01/02/25)

1 reviewer was added to this PR based on xxchan's automation.

@cyliu0 cyliu0 added this pull request to the merge queue Jan 22, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jan 22, 2025
Merged via the queue into release-2.2 with commit 6ea7800 Jan 22, 2025
25 checks passed
@cyliu0 cyliu0 deleted the auto-release-2.2-5cb0d17182de20354df198477b9955d5689e82ba-1735813276 branch January 22, 2025 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants