Skip to content

Commit c413ac5

Browse files
committed
[fix](be) Migrate zone map benchmark to column API
### What problem does this PR solve?\n\nIssue Number: None\n\nRelated PR: #69070\n\nProblem Summary: ZoneMapIndexWriter now consumes IColumn row ranges, but the supported zone-map benchmark still called the removed add_values interface. Build the benchmark data as columns outside timed loops and feed the new column-range API.\n\n### Release note\n\nNone\n\n### Check List (For Author)\n\n- Test: Clang format, build hygiene, isolated benchmark header syntax check\n- Behavior changed: No\n- Does this need documentation: No
1 parent ac75442 commit c413ac5

1 file changed

Lines changed: 43 additions & 26 deletions

File tree

‎be/benchmark/benchmark_zone_map_index.hpp‎

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// under the License.
1717

1818
// ============================================================
19-
// Benchmark: TypedZoneMapIndexWriter::add_values
19+
// Benchmark: TypedZoneMapIndexWriter::add
2020
//
2121
// Measures CPU cost of feeding values into the per-page zone-map
2222
// builder for a few representative primitive types and call sizes.
@@ -32,7 +32,10 @@
3232
#include <string>
3333
#include <vector>
3434

35+
#include "core/column/column_string.h"
36+
#include "core/column/column_vector.h"
3537
#include "core/data_type/data_type_factory.hpp"
38+
#include "core/data_type/primitive_type.h"
3639
#include "core/string_ref.h"
3740
#include "storage/index/zone_map/zone_map_index.h"
3841
#include "storage/tablet/tablet_schema.h"
@@ -98,6 +101,20 @@ inline TabletColumnPtr make_column(FieldType ft, int32_t length, int32_t index_l
98101
return c;
99102
}
100103

104+
// The generated values as the column a writer is handed.
105+
template <PrimitiveType PType, typename Vec>
106+
ColumnPtr to_column(const Vec& values) {
107+
auto column = PrimitiveTypeTraits<PType>::ColumnType::create();
108+
for (const auto& value : values) {
109+
if constexpr (PType == TYPE_VARCHAR) {
110+
column->insert_data(value.data, value.size);
111+
} else {
112+
column->insert_value(value);
113+
}
114+
}
115+
return column;
116+
}
117+
101118
template <PrimitiveType PType>
102119
std::unique_ptr<ZoneMapIndexWriter> make_writer() {
103120
TabletColumnPtr col;
@@ -120,16 +137,16 @@ std::unique_ptr<ZoneMapIndexWriter> make_writer() {
120137
return w;
121138
}
122139

123-
template <PrimitiveType PType, typename Vec>
124-
void run(benchmark::State& state, const Vec& values) {
140+
template <PrimitiveType PType>
141+
void run(benchmark::State& state, const IColumn& column) {
125142
const size_t batch = static_cast<size_t>(state.range(0));
126-
const size_t total = values.size();
143+
const size_t total = column.size();
127144
for (auto _ : state) {
128145
auto w = make_writer<PType>();
129146
size_t off = 0;
130147
while (off < total) {
131148
size_t n = std::min(batch, total - off);
132-
w->add_values(reinterpret_cast<const void*>(&values[off]), n);
149+
w->add(column, off, n);
133150
off += n;
134151
}
135152
(void)w->flush();
@@ -141,19 +158,19 @@ void run(benchmark::State& state, const Vec& values) {
141158
// Simulates the ScalarColumnWriter call pattern in compaction:
142159
// - merge iterator hands `block_rows`-row blocks to ColumnWriter::append
143160
// - column_writer chunks each block by page remaining capacity and calls
144-
// add_values() per chunk
161+
// add() per chunk
145162
// - when a page is full, finish_current_page() calls flush() on the zone
146163
// map builder, then a new page begins
147164
//
148165
// Compaction batch_size is computed dynamically as
149166
// `block_mem_limit / group_data_size` clamped to [32, 4064]
150167
// (be/src/storage/merger.cpp:458). For wide rows / variant data it routinely
151168
// drops to the low end (32 - 256), which is the case the flame graph exposes.
152-
template <PrimitiveType PType, typename Vec>
153-
void run_column_writer_like(benchmark::State& state, const Vec& values, size_t elem_size) {
169+
template <PrimitiveType PType>
170+
void run_column_writer_like(benchmark::State& state, const IColumn& column, size_t elem_size) {
154171
const size_t block_rows = static_cast<size_t>(state.range(0));
155172
const size_t page_capacity = kStoragePageSize / elem_size; // e.g. 16384 for int32
156-
const size_t total = values.size();
173+
const size_t total = column.size();
157174
for (auto _ : state) {
158175
auto w = make_writer<PType>();
159176
size_t off = 0;
@@ -162,7 +179,7 @@ void run_column_writer_like(benchmark::State& state, const Vec& values, size_t e
162179
size_t block_left = std::min(block_rows, total - off);
163180
while (block_left > 0) {
164181
size_t n = std::min(block_left, page_capacity - page_used);
165-
w->add_values(reinterpret_cast<const void*>(&values[off]), n);
182+
w->add(column, off, n);
166183
off += n;
167184
block_left -= n;
168185
page_used += n;
@@ -179,20 +196,20 @@ void run_column_writer_like(benchmark::State& state, const Vec& values, size_t e
179196
}
180197

181198
static void BM_ZoneMap_Int32(benchmark::State& state) {
182-
static auto vals = gen_int32(kTotalRows);
183-
run<TYPE_INT>(state, vals);
199+
static auto vals = to_column<TYPE_INT>(gen_int32(kTotalRows));
200+
run<TYPE_INT>(state, *vals);
184201
}
185202
static void BM_ZoneMap_Int64(benchmark::State& state) {
186-
static auto vals = gen_int64(kTotalRows);
187-
run<TYPE_BIGINT>(state, vals);
203+
static auto vals = to_column<TYPE_BIGINT>(gen_int64(kTotalRows));
204+
run<TYPE_BIGINT>(state, *vals);
188205
}
189206
static void BM_ZoneMap_Double(benchmark::State& state) {
190-
static auto vals = gen_double(kTotalRows);
191-
run<TYPE_DOUBLE>(state, vals);
207+
static auto vals = to_column<TYPE_DOUBLE>(gen_double(kTotalRows));
208+
run<TYPE_DOUBLE>(state, *vals);
192209
}
193210
static void BM_ZoneMap_String(benchmark::State& state) {
194-
static auto batch = gen_strings(kTotalRows, 16);
195-
run<TYPE_VARCHAR>(state, batch.slices);
211+
static auto vals = to_column<TYPE_VARCHAR>(gen_strings(kTotalRows, 16).slices);
212+
run<TYPE_VARCHAR>(state, *vals);
196213
}
197214

198215
BENCHMARK(BM_ZoneMap_Int32)->Arg(1)->Arg(64)->Arg(1024);
@@ -202,21 +219,21 @@ BENCHMARK(BM_ZoneMap_String)->Arg(1)->Arg(64)->Arg(1024);
202219

203220
// Realistic compaction-shaped: 1024-row blocks + page-driven flush().
204221
static void BM_ZoneMap_ColWriter_Int32(benchmark::State& state) {
205-
static auto vals = gen_int32(kTotalRows);
206-
run_column_writer_like<TYPE_INT>(state, vals, sizeof(int32_t));
222+
static auto vals = to_column<TYPE_INT>(gen_int32(kTotalRows));
223+
run_column_writer_like<TYPE_INT>(state, *vals, sizeof(int32_t));
207224
}
208225
static void BM_ZoneMap_ColWriter_Int64(benchmark::State& state) {
209-
static auto vals = gen_int64(kTotalRows);
210-
run_column_writer_like<TYPE_BIGINT>(state, vals, sizeof(int64_t));
226+
static auto vals = to_column<TYPE_BIGINT>(gen_int64(kTotalRows));
227+
run_column_writer_like<TYPE_BIGINT>(state, *vals, sizeof(int64_t));
211228
}
212229
static void BM_ZoneMap_ColWriter_Double(benchmark::State& state) {
213-
static auto vals = gen_double(kTotalRows);
214-
run_column_writer_like<TYPE_DOUBLE>(state, vals, sizeof(double));
230+
static auto vals = to_column<TYPE_DOUBLE>(gen_double(kTotalRows));
231+
run_column_writer_like<TYPE_DOUBLE>(state, *vals, sizeof(double));
215232
}
216233
static void BM_ZoneMap_ColWriter_String(benchmark::State& state) {
217-
static auto batch = gen_strings(kTotalRows, 16);
234+
static auto vals = to_column<TYPE_VARCHAR>(gen_strings(kTotalRows, 16).slices);
218235
// For strings the page packs (size+payload); use ~32B avg per element.
219-
run_column_writer_like<TYPE_VARCHAR>(state, batch.slices, 32);
236+
run_column_writer_like<TYPE_VARCHAR>(state, *vals, 32);
220237
}
221238
BENCHMARK(BM_ZoneMap_ColWriter_Int32)
222239
->Arg(1)

0 commit comments

Comments
 (0)