aokolnychyi commented on code in PR #7558:
URL: https://github.com/apache/iceberg/pull/7558#discussion_r1187836896


##########
spark/v3.4/spark-extensions/src/jmh/java/org/apache/iceberg/spark/MergeCardinalityCheckBenchmark.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * 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.
+ */
+package org.apache.iceberg.spark;
+
+import static org.apache.spark.sql.functions.current_date;
+import static org.apache.spark.sql.functions.date_add;
+import static org.apache.spark.sql.functions.expr;
+
+import java.util.UUID;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.DistributionMode;
+import org.apache.iceberg.RowLevelOperationMode;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.SparkSession;
+import org.apache.spark.sql.catalyst.analysis.NoSuchTableException;
+import org.apache.spark.sql.catalyst.parser.ParseException;
+import org.apache.spark.sql.internal.SQLConf;
+import org.apache.spark.sql.types.StructType;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.annotations.Warmup;
+
+/**
+ * A benchmark that evaluates the performance of the cardinality check in 
MERGE operations.
+ *
+ * <p>To run this benchmark for spark-3.3: <code>
+ *   ./gradlew -DsparkVersions=3.4 
:iceberg-spark:iceberg-spark-extensions-3.4_2.12:jmh
+ *       -PjmhIncludeRegex=MergeCardinalityCheckBenchmark
+ *       
-PjmhOutputPath=benchmark/iceberg-merge-cardinality-check-benchmark.txt
+ * </code>
+ */
+@Fork(1)
+@State(Scope.Benchmark)
+@Warmup(iterations = 3)
+@Measurement(iterations = 5)
+@BenchmarkMode(Mode.SingleShotTime)
+public class MergeCardinalityCheckBenchmark {

Review Comment:
   ```
   Benchmark                                                                    
                 Mode  Cnt            Score             Error   Units
   [NEW] copyOnWriteMergeCardinalityCheck10PercentUpdates                       
                   ss    5           14.008 ±           1.114    s/op
   [OLD] copyOnWriteMergeCardinalityCheck10PercentUpdates                       
                   ss    5           16.711 ±           0.288    s/op
   
   [NEW] copyOnWriteMergeCardinalityCheck30PercentUpdates                       
                   ss    5           14.293 ±           2.359    s/op
   [OLD] copyOnWriteMergeCardinalityCheck30PercentUpdates                       
                   ss    5           17.242 ±           2.855    s/op
   
   [NEW] copyOnWriteMergeCardinalityCheck90PercentUpdates                       
                   ss    5           14.536 ±           1.344    s/op
   [OLD] copyOnWriteMergeCardinalityCheck90PercentUpdates                       
                   ss    5           18.966 ±           6.966    s/op
   
   [NEW] mergeOnReadMergeCardinalityCheck10PercentUpdates                       
                   ss    5            9.585 ±           0.467    s/op
   [OLD] mergeOnReadMergeCardinalityCheck10PercentUpdates                       
                   ss    5           10.493 ±           5.130    s/op
   
   [NEW] mergeOnReadMergeCardinalityCheck30PercentUpdates                       
                   ss    5           14.910 ±           0.264    s/op
   [OLD] mergeOnReadMergeCardinalityCheck30PercentUpdates                       
                   ss    5           15.171 ±           0.275    s/op
   
   [NEW] mergeOnReadMergeCardinalityCheck90PercentUpdates                       
                   ss    5           30.746 ±           0.237    s/op
   [OLD] mergeOnReadMergeCardinalityCheck90PercentUpdates                       
                   ss    5           32.714 ±           0.544    s/op
   ```
   
   Here is a shorter representation. There is a small reduction in terms memory 
too. Like said above, this run still does a local sort and trigger a spill, we 
just reduce the amount of spilled data. If we skip the final sort, we can 
actually avoid the local sort altogether.



-- 
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