You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "wankunde (via GitHub)" <gi...@apache.org> on 2023/08/01 06:53:56 UTC

[GitHub] [spark] wankunde commented on a diff in pull request #41782: [SPARK-44239][SQL] Free memory allocated by large vectors when vectors are reset

wankunde commented on code in PR #41782:
URL: https://github.com/apache/spark/pull/41782#discussion_r1280181675


##########
sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/VectorReservePolicy.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.spark.sql.execution.vectorized;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import org.apache.spark.sql.internal.SQLConf;
+import org.apache.spark.unsafe.array.ByteArrayMethods;
+
+public abstract class VectorReservePolicy {
+
+  protected int defaultCapacity;
+
+  /**
+   * Upper limit for the maximum capacity for this column.
+   */
+  @VisibleForTesting
+  protected int MAX_CAPACITY = ByteArrayMethods.MAX_ROUNDED_ARRAY_LENGTH;
+
+  /**
+   * True if this column has default values. Return the default values instead of NULL when the
+   * corresponding columns are not present in storage. We can not reset the data of column vectors
+   * that has default values.
+   */
+  protected boolean hasDefaultValue = false;
+
+  abstract int nextCapacity(int requiredCapacity);
+
+  boolean shouldCleanData() {
+    return false;
+  }
+}
+
+class DefaultVectorReservePolicy extends VectorReservePolicy {
+
+  private int hugeThreshold;
+  private double hugeReserveRatio;
+  private int currentCapacity;
+
+  DefaultVectorReservePolicy(int defaultCapacity) {
+    this.defaultCapacity = defaultCapacity;
+    this.currentCapacity = defaultCapacity;
+    SQLConf conf = SQLConf.get();
+    hugeThreshold = conf.vectorizedHugeVectorThreshold();
+    hugeReserveRatio = conf.vectorizedHugeVectorReserveRatio();
+  }
+
+  @Override
+  public int nextCapacity(int requiredCapacity) {
+    if (hugeThreshold < 0 || requiredCapacity < hugeThreshold) {
+      currentCapacity = (int) Math.min(MAX_CAPACITY, requiredCapacity * 2L);
+    } else {
+      currentCapacity = (int) Math.min(MAX_CAPACITY, requiredCapacity * hugeReserveRatio);

Review Comment:
   Thanks for your idea, I have updated the formula.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org