Skip to content

Commit

Permalink
inmemory layer flush: avoid allocation when checking whether key_rang…
Browse files Browse the repository at this point in the history
…e is empty

Found this while doing research for #7418
  • Loading branch information
problame committed Jun 25, 2024
1 parent 219e78f commit fcf5518
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pageserver/src/tenant/storage_layer/inmemory_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,18 +622,16 @@ impl InMemoryLayer {

let end_lsn = *self.end_lsn.get().unwrap();

let keys: Vec<_> = if let Some(key_range) = key_range {
let key_count = if let Some(key_range) = key_range {
inner
.index
.iter()
.filter(|(k, _)| key_range.contains(k))
.map(|(k, m)| (k.to_i128(), m))
.collect()
.count()
} else {
inner.index.iter().map(|(k, m)| (k.to_i128(), m)).collect()
inner.index.len()
};

if keys.is_empty() {
if key_count == 0 {
return Ok(None);
}

Expand Down

0 comments on commit fcf5518

Please sign in to comment.