This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch dev/1.1
in repository https://gitbox.apache.org/repos/asf/tsfile.git
The following commit(s) were added to refs/heads/dev/1.1 by this push:
new 3c191475 perf: Optimize aligned object memory size calculation (#577)
(#581)
3c191475 is described below
commit 3c1914753a788fd802f74afb4e0bd75ba09cdb47
Author: Zhenyu Luo <[email protected]>
AuthorDate: Mon Sep 1 10:10:54 2025 +0800
perf: Optimize aligned object memory size calculation (#577) (#581)
* Optimize aligned object memory size calculation
* spotless
---
.../src/main/java/org/apache/tsfile/utils/RamUsageEstimator.java | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git
a/java/common/src/main/java/org/apache/tsfile/utils/RamUsageEstimator.java
b/java/common/src/main/java/org/apache/tsfile/utils/RamUsageEstimator.java
index 404af510..af7a8cff 100644
--- a/java/common/src/main/java/org/apache/tsfile/utils/RamUsageEstimator.java
+++ b/java/common/src/main/java/org/apache/tsfile/utils/RamUsageEstimator.java
@@ -82,6 +82,8 @@ public final class RamUsageEstimator {
*/
public static final int NUM_BYTES_OBJECT_ALIGNMENT;
+ private static final int ALIGN_MASK;
+
/**
* Approximate memory usage that we assign to all unknown queries - this
maps roughly to a
* BooleanQuery with a couple term clauses.
@@ -180,6 +182,8 @@ public final class RamUsageEstimator {
NUM_BYTES_ARRAY_HEADER = NUM_BYTES_OBJECT_HEADER + Integer.BYTES;
}
+ ALIGN_MASK = NUM_BYTES_OBJECT_ALIGNMENT - 1;
+
// get min/max value of cached Long class instances:
long longCacheMinValue = 0;
while (longCacheMinValue > Long.MIN_VALUE
@@ -209,8 +213,7 @@ public final class RamUsageEstimator {
/** Aligns an object size to be the next multiple of {@link
#NUM_BYTES_OBJECT_ALIGNMENT}. */
public static long alignObjectSize(long size) {
- size += NUM_BYTES_OBJECT_ALIGNMENT - 1L;
- return size - (size % NUM_BYTES_OBJECT_ALIGNMENT);
+ return (size + ALIGN_MASK) & ~ALIGN_MASK;
}
/**