xndai commented on code in PR #1126:
URL: https://github.com/apache/iceberg-cpp/pull/1126#discussion_r4701904114


##########
src/iceberg/benchmark/mumbling_bitmap_benchmark.cc:
##########
@@ -0,0 +1,245 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// Microbenchmarks for the Mumbling bitmap reader.
+//
+// Build with -DICEBERG_BUILD_BENCHMARKS=ON and run, for example:
+//   ./build/src/iceberg/benchmark/mumbling_bitmap_benchmark 
--benchmark_filter=Pfor
+//
+// The inputs are serialized with the test encoder in
+// iceberg/test/mumbling_bitmap_test_util.h, which picks PFOR bit widths the 
way
+// the Java encoder does (checked against Java-generated fixtures in
+// mumbling_bitmap_internal_test.cc).
+
+#include <algorithm>
+#include <cstdint>
+#include <cstdlib>
+#include <random>
+#include <set>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include <benchmark/benchmark.h>
+
+#include "iceberg/test/mumbling_bitmap_test_util.h"
+#include "iceberg/util/mumbling_bitmap_internal.h"
+
+namespace iceberg {
+namespace {
+
+using mumbling_test::BuildBitmapFromPositions;
+using mumbling_test::Bytes;
+using mumbling_test::EncodePfor;
+using mumbling_test::kBestWidth;
+
+constexpr int64_t kMaxPositions = MumblingBitmapView::kMaxCardinality;
+constexpr uint32_t kSeed = 42;
+
+// ---------------------------------------------------------------------------
+// PFOR descriptor decoding
+// ---------------------------------------------------------------------------
+
+// Value distributions for PFOR inputs, modeled on Java's PFORRandomData.
+enum class PforData {
+  kConstant,         // every value is the same (one bit width of 0)
+  kSmall,            // uniform 0-3
+  kExceptions1Pct,   // 0-3 with 1% exceptions in 0-255
+  kExceptions10Pct,  // 0-3 with 10% exceptions in 0-255
+  kUniform,          // uniform 0-255 (stored as raw bytes)
+};
+
+std::vector<uint8_t> MakePforValues(PforData data, size_t count) {
+  std::mt19937 rng(kSeed);
+  std::uniform_int_distribution<int> small(0, 3);
+  std::uniform_int_distribution<int> any(0, 255);
+  std::uniform_real_distribution<double> unit(0.0, 1.0);
+  std::vector<uint8_t> values(count);
+  for (auto& value : values) {
+    switch (data) {
+      case PforData::kConstant:
+        value = 5;
+        break;
+      case PforData::kSmall:
+        value = static_cast<uint8_t>(small(rng));
+        break;
+      case PforData::kExceptions1Pct:
+        value = static_cast<uint8_t>(unit(rng) < 0.01 ? any(rng) : small(rng));
+        break;
+      case PforData::kExceptions10Pct:
+        value = static_cast<uint8_t>(unit(rng) < 0.10 ? any(rng) : small(rng));
+        break;
+      case PforData::kUniform:
+        value = static_cast<uint8_t>(any(rng));
+        break;
+    }
+  }
+  return values;
+}
+
+// Arg: number of values.
+void BM_PforDecode(benchmark::State& state, PforData data) {
+  const auto count = static_cast<size_t>(state.range(0));
+  const Bytes encoded = EncodePfor(MakePforValues(data, count), kBestWidth);
+  std::vector<uint8_t> out(count);
+  while (state.KeepRunning()) {
+    auto result = DecodePforBytes(encoded, out);
+    benchmark::DoNotOptimize(result);

Review Comment:
   yes



##########
src/iceberg/util/mumbling_bitmap_internal.h:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+/// \file iceberg/util/mumbling_bitmap_internal.h
+/// A read-only Mumbling bitmap, the compressed bitmap format used by v4
+/// manifest deletion vectors.
+///
+/// Spec: https://github.com/apache/iceberg/blob/main/format/mumbling-spec.md
+/// The spec is still a draft, so this header is internal and not installed.
+
+#include <cstddef>
+#include <cstdint>
+#include <span>
+#include <vector>
+
+#include "iceberg/iceberg_export.h"
+#include "iceberg/result.h"
+
+namespace iceberg {
+
+/// \brief Decodes a PFOR-encoded array of unsigned bytes.
+///
+/// Implements "Appendix A: PFOR encoding for unsigned bytes" of the Mumbling
+/// bitmap spec
+/// 
(https://github.com/apache/iceberg/blob/main/format/mumbling-spec.md#appendix-a-pfor-encoding-for-unsigned-bytes),
+/// which encodes the descriptor array. Values are encoded in
+/// chunks of 256 values (the last chunk holds the remainder), each with a
+/// 3-byte header, a bit-packed primary array, exception offsets and
+/// bit-packed exception values.
+///
+/// \param data the encoded bytes; may extend past the encoded values.
+/// \param out receives the decoded values; its size is the number of values.

Review Comment:
   sure



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to