Commit 0c377de
perf: Avoid unnecessary object copy (#14843)
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: D1076766271 parent 7affaee commit 0c377de
1 file changed
Lines changed: 11 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1065 | 1065 | | |
1066 | 1066 | | |
1067 | 1067 | | |
1068 | | - | |
| 1068 | + | |
1069 | 1069 | | |
1070 | | - | |
1071 | | - | |
| 1070 | + | |
| 1071 | + | |
1072 | 1072 | | |
1073 | | - | |
1074 | | - | |
| 1073 | + | |
| 1074 | + | |
1075 | 1075 | | |
1076 | 1076 | | |
1077 | | - | |
| 1077 | + | |
1078 | 1078 | | |
1079 | 1079 | | |
1080 | 1080 | | |
1081 | 1081 | | |
1082 | | - | |
| 1082 | + | |
1083 | 1083 | | |
1084 | 1084 | | |
1085 | 1085 | | |
1086 | | - | |
| 1086 | + | |
1087 | 1087 | | |
1088 | 1088 | | |
1089 | 1089 | | |
| |||
1115 | 1115 | | |
1116 | 1116 | | |
1117 | 1117 | | |
1118 | | - | |
| 1118 | + | |
1119 | 1119 | | |
1120 | 1120 | | |
1121 | 1121 | | |
| |||
7863 | 7863 | | |
7864 | 7864 | | |
7865 | 7865 | | |
7866 | | - | |
| 7866 | + | |
| 7867 | + | |
7867 | 7868 | | |
7868 | 7869 | | |
7869 | 7870 | | |
| |||
0 commit comments