Skip to content

Optimize stale key iteration when digest is up to date - #189

Merged
guilload merged 1 commit into
quickwit-oss:mainfrom
Stool233:optimize-stale-key-values
Nov 9, 2026
Merged

guilload merged 1 commit into
quickwit-oss:mainfrom
Stool233:optimize-stale-key-values

Conversation

@Stool233

Copy link
Copy Markdown
Contributor

Closes #73.

What

This updates NodeState::stale_key_values to return an empty iterator immediately when floor_version is greater than or equal to the node state's max_version.

Why

No key-value in a NodeState can have a version greater than max_version, so when floor_version >= max_version, there cannot be any stale key-value with version > floor_version.

The main delta computation path already skips nodes whose max_version is not greater than the digest's max_version before calling this helper. This change applies the same fast path inside NodeState::stale_key_values itself, removes the existing TODO, and keeps the helper efficient for direct or future call sites.

This does not change the public API, gossip semantics, delta contents, or wire format.

Validation

  • cargo test -p chitchat --lib stale_key_values
  • cargo test -p chitchat test_sorted_stale_nodes_offer
  • cargo test -p chitchat --lib

@guilload

guilload commented Nov 5, 2026

Copy link
Copy Markdown
Member

Thanks for picking up this TODO! The change is correct: every key's version is at most max_version, so we can skip the scan when floor_version >= max_version.

Could you replace the Option/flatten combo with an early return? I find it easier to read:

// No key can have a version greater than `max_version`.
if self.max_version <= floor_version {
    return Either::Left(std::iter::empty());
}
let stale_key_values = self
    .key_values_including_deleted()
    .filter(move |(_key, versioned_value)| versioned_value.version > floor_version);
Either::Right(stale_key_values)

(with use itertools::{Either, Itertools};)

Also, please rebase onto main.

@Stool233
Stool233 force-pushed the optimize-stale-key-values branch from c0f99ae to 29f4693 Compare November 6, 2026 02:02
@Stool233

Stool233 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the suggestion! I’ve updated the code to use Either with an early return and rebased the branch onto main. Ready for another look whenever you have time.

@guilload
guilload merged commit 2e8aee1 into quickwit-oss:main Nov 9, 2026
2 checks passed
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.

Optimize iter_stale_key_values by checking the max version

2 participants