adriacabeza commented on code in PR #2485:
URL: https://github.com/apache/fory/pull/2485#discussion_r2280953118


##########
java/fory-core/src/main/java/org/apache/fory/util/ArrayCompressionUtils.java:
##########
@@ -0,0 +1,338 @@
+/*
+ * 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.fory.util;
+
+import jdk.incubator.vector.IntVector;
+import jdk.incubator.vector.LongVector;
+import jdk.incubator.vector.VectorOperators;
+import jdk.incubator.vector.VectorSpecies;
+
+/**
+ * SIMD-accelerated compression utilities for primitive arrays.
+ *
+ * <p>This utility provides compression for primitive arrays by detecting when 
values can fit in
+ * smaller data types:
+ *
+ * <ul>
+ *   <li>int[] → byte[] when all values are in [-128, 127] range (75% size 
reduction)
+ *   <li>int[] → short[] when all values are in [-32768, 32767] range (50% 
size reduction)
+ *   <li>long[] → int[] when all values fit in integer range (50% size 
reduction)
+ * </ul>
+ *
+ * <p>Uses SIMD operations (Vector API) when available on Java 16+ for optimal 
performance. Falls
+ * back to scalar processing on older versions or when arrays are too small.
+ *
+ * <p>Compression is only applied to arrays with at least 16 elements to 
justify the analysis
+ * overhead.
+ */
+public final class ArrayCompressionUtils {
+
+  // Java version and Vector API availability check
+  private static final int JAVA_VERSION = getJavaVersion();
+  private static final boolean COMPRESSION_ENABLED = JAVA_VERSION >= 16;
+  private static final boolean VECTOR_API_AVAILABLE;
+  private static final VectorSpecies<Integer> INT_SPECIES;
+  private static final VectorSpecies<Long> LONG_SPECIES;
+  private static final int INT_VECTOR_LENGTH;
+  private static final int LONG_VECTOR_LENGTH;
+
+  // Minimum array size to justify compression overhead
+  private static final int MIN_COMPRESSION_SIZE = 16;

Review Comment:
   this value was chosen completely randomly, probably something better can be 
chosen



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