Abacn commented on code in PR #41540:
URL: https://github.com/apache/beam/pull/41540#discussion_r4682739041
##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/Caches.java:
##########
@@ -68,23 +73,153 @@ public final class Caches {
private static final MemoryMeter MEMORY_METER =
MemoryMeter.builder().build();
+ /**
+ * Maximum {@link String#length()} scanned inline to distinguish Latin-1 vs
UTF-16 storage under
+ * compact strings. Longer strings fall back to {@code O(1)} {@link
MemoryMeter#measureDeep} when
+ * accessible, or the conservative UTF-16 upper bound otherwise.
+ */
+ @VisibleForTesting static final int STRING_SCAN_LIMIT = 128;
+
+ /**
+ * Exact {@code LiteralByteString} class ({@link ByteString#EMPTY}).
Restricting the fast path to
+ * this concrete class ensures sliced {@code BoundedByteString}, {@code
RopeByteString}, and
+ * {@code NioByteString} instances fall back to deep measurement so retained
backing buffers are
+ * not under-counted.
+ */
+ private static final Class<?> LITERAL_BYTE_STRING_CLASS =
ByteString.EMPTY.getClass();
+
+ /** Whether {@link MemoryMeter#measureDeep} can inspect {@link String}'s
internal array. */
+ private static final boolean CAN_MEASURE_STRING_DEEP;
+
+ /** Whether this JVM uses JDK 9+ compact (Latin-1 byte[]) String storage. */
+ private static final boolean COMPACT_STRINGS;
Review Comment:
This chunk sounds very hacky though
--
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]