Skip to content

Commit

Permalink
Tweak on IsTrivialMove() (facebook#11467)
Browse files Browse the repository at this point in the history
Summary:
`output_level_` and `number_levels_` are not changing in iteration of `inputs_` files.

Moving the check out of `for` loop could slightly improve performance.

It is easier to review when ignore whitespace changes.

Pull Request resolved: facebook#11467

Reviewed By: cbi42

Differential Revision: D46155962

Pulled By: ajkr

fbshipit-source-id: 45ec80b13152b3bed7305e6f707cb9b187d5f315
  • Loading branch information
solicomo authored and facebook-github-bot committed May 26, 2023
1 parent 23f4e9a commit de1dd4c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ fuzz/crash-*

cmake-build-*
third-party/folly/
.cache
.cache
*.sublime-*
35 changes: 17 additions & 18 deletions db/compaction/compaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,26 +486,25 @@ bool Compaction::IsTrivialMove() const {

// assert inputs_.size() == 1

std::unique_ptr<SstPartitioner> partitioner = CreateSstPartitioner();

for (const auto& file : inputs_.front().files) {
std::vector<FileMetaData*> file_grand_parents;
if (output_level_ + 1 >= number_levels_) {
continue;
}
input_vstorage_->GetOverlappingInputs(output_level_ + 1, &file->smallest,
&file->largest, &file_grand_parents);
const auto compaction_size =
file->fd.GetFileSize() + TotalFileSize(file_grand_parents);
if (compaction_size > max_compaction_bytes_) {
return false;
}

if (partitioner.get() != nullptr) {
if (!partitioner->CanDoTrivialMove(file->smallest.user_key(),
file->largest.user_key())) {
if (output_level_ + 1 < number_levels_) {
std::unique_ptr<SstPartitioner> partitioner = CreateSstPartitioner();
for (const auto& file : inputs_.front().files) {
std::vector<FileMetaData*> file_grand_parents;
input_vstorage_->GetOverlappingInputs(output_level_ + 1, &file->smallest,
&file->largest,
&file_grand_parents);
const auto compaction_size =
file->fd.GetFileSize() + TotalFileSize(file_grand_parents);
if (compaction_size > max_compaction_bytes_) {
return false;
}

if (partitioner.get() != nullptr) {
if (!partitioner->CanDoTrivialMove(file->smallest.user_key(),
file->largest.user_key())) {
return false;
}
}
}
}

Expand Down

0 comments on commit de1dd4c

Please sign in to comment.