This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/tsfile.git
The following commit(s) were added to refs/heads/develop by this push:
new 674a65ca perf: Optimize aligned object memory size calculation (#577)
674a65ca is described below
commit 674a65ca7a5e4a38023f9b0e7fb685ece5642cb0
Author: Zhenyu Luo <[email protected]>
AuthorDate: Wed Aug 27 10:35:47 2025 +0800
perf: Optimize aligned object memory size calculation (#577)
* 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;
}
/**