perf: Avoid unnecessary object copy (#14843)#14843
Conversation
|
@MatzeB has exported this pull request. If you are a Meta employee, you can view the originating Diff in D107676627. |
✅ clang-tidy: No findings on changed linesCompleted in 267.3s. |
Summary: This function shows up in internal profiles. This is an AI generated performance optimization (but human reviewed): Optimized `rocksdb::ColumnFamilyOptions::ColumnFamilyOptions` by eliminating unnecessary copy construction calls in the hottest callers. **Problem:** Strobelight traces (weight 705M+) showed the `ColumnFamilyOptions` copy constructor being called from `GetMinTimeBasedCompactionInterval(cfd->GetLatestCFOptions())` in both `TriggerPeriodicCompaction` and `ComputeTriggerCompactionPeriod`. `GetLatestCFOptions()` calls `BuildColumnFamilyOptions` which copy-constructs an entire `ColumnFamilyOptions` object just to read a few scalar fields. **Fix:** Changed `GetMinTimeBasedCompactionInterval` to accept `const MutableCFOptions&` instead of `const ColumnFamilyOptions&`. All fields it reads (`periodic_compaction_seconds`, `ttl`, `compaction_options_fifo.file_temperature_age_thresholds`, `bottommost_file_compaction_delay`) exist in `MutableCFOptions`. Updated both call sites to pass `cfd->GetLatestMutableCFOptions()` which returns a `const&` — no copy needed. **Impact:** Eliminates the expensive `ColumnFamilyOptions` copy construction (which involves copying multiple `shared_ptr` members with atomic ref-count increments, vectors, and strings) on every periodic compaction check and trigger computation period calculation, for every column family in the loop. Differential Revision: D107676627
7c67510 to
0c377de
Compare
Summary: This function shows up in internal profiles. This is an AI generated performance optimization (but human reviewed): Optimized `rocksdb::ColumnFamilyOptions::ColumnFamilyOptions` by eliminating unnecessary copy construction calls in the hottest callers. **Problem:** Strobelight traces (weight 705M+) showed the `ColumnFamilyOptions` copy constructor being called from `GetMinTimeBasedCompactionInterval(cfd->GetLatestCFOptions())` in both `TriggerPeriodicCompaction` and `ComputeTriggerCompactionPeriod`. `GetLatestCFOptions()` calls `BuildColumnFamilyOptions` which copy-constructs an entire `ColumnFamilyOptions` object just to read a few scalar fields. **Fix:** Changed `GetMinTimeBasedCompactionInterval` to accept `const MutableCFOptions&` instead of `const ColumnFamilyOptions&`. All fields it reads (`periodic_compaction_seconds`, `ttl`, `compaction_options_fifo.file_temperature_age_thresholds`, `bottommost_file_compaction_delay`) exist in `MutableCFOptions`. Updated both call sites to pass `cfd->GetLatestMutableCFOptions()` which returns a `const&` — no copy needed. **Impact:** Eliminates the expensive `ColumnFamilyOptions` copy construction (which involves copying multiple `shared_ptr` members with atomic ref-count increments, vectors, and strings) on every periodic compaction check and trigger computation period calculation, for every column family in the loop. Differential Revision: D107676627
0c377de to
8396445
Compare
🟡 Codex Code ReviewAuto-triggered after CI passed — reviewing commit 8396445 ❌ Codex review failed before producing findings. ℹ️ About this responseGenerated by Codex CLI. Limitations:
Commands:
|
✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 8396445 SummaryClean performance optimization that eliminates unnecessary High-severity findings (0): No high-severity findings. Full review (click to expand)Findings🔴 HIGHNone. 🟡 MEDIUMNone. 🟢 LOW / NITNone. Cross-Component Analysis
Field verification (MutableCFOptions vs ColumnFamilyOptions):
Reference safety: Caller scope: Positive Observations
ℹ️ About this responseGenerated by Claude Code. Limitations:
Commands:
|
Summary:
This function shows up in internal profiles. This is an AI generated performance optimization (but human reviewed):
Optimized
rocksdb::ColumnFamilyOptions::ColumnFamilyOptionsby eliminating unnecessary copy construction calls in the hottest callers.Problem: Strobelight traces (weight 705M+) showed the
ColumnFamilyOptionscopy constructor being called fromGetMinTimeBasedCompactionInterval(cfd->GetLatestCFOptions())in bothTriggerPeriodicCompactionandComputeTriggerCompactionPeriod.GetLatestCFOptions()callsBuildColumnFamilyOptionswhich copy-constructs an entireColumnFamilyOptionsobject just to read a few scalar fields.Fix: Changed
GetMinTimeBasedCompactionIntervalto acceptconst MutableCFOptions&instead ofconst ColumnFamilyOptions&. All fields it reads (periodic_compaction_seconds,ttl,compaction_options_fifo.file_temperature_age_thresholds,bottommost_file_compaction_delay) exist inMutableCFOptions. Updated both call sites to passcfd->GetLatestMutableCFOptions()which returns aconst&— no copy needed.Impact: Eliminates the expensive
ColumnFamilyOptionscopy construction (which involves copying multipleshared_ptrmembers with atomic ref-count increments, vectors, and strings) on every periodic compaction check and trigger computation period calculation, for every column family in the loop.Differential Revision: D107676627