reuvenlax commented on code in PR #41540:
URL: https://github.com/apache/beam/pull/41540#discussion_r4773404734
##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/StateFetchingIterators.java:
##########
@@ -258,27 +259,40 @@ private Builder(int initialCapacity) {
void addAndWeighAll(List<T> addedValues) {
values.addAll(addedValues);
+ weight =
+ LongMath.saturatedAdd(
+ weight, LongMath.saturatedMultiply(addedValues.size(),
Caches.REFERENCE_SIZE));
for (@Nullable T v : addedValues) {
weight = LongMath.saturatedAdd(weight, Caches.weigh(v));
}
}
+ /**
+ * Adds {@code addedValues} with a pre-computed weight that already
includes {@code
+ * addedValues.size() * Caches.REFERENCE_SIZE}.
+ */
void addAllWithWeight(List<T> addedValues, long addedWeight) {
values.addAll(addedValues);
weight = LongMath.saturatedAdd(weight, addedWeight);
}
void addBlock(Block<T> b) {
values.addAll(b.getValues());
- weight = LongMath.saturatedAdd(weight, b.getWeight());
+ long blockWeight = b.getWeight();
+ // Non-empty blocks already include ARRAY_LIST_OVERHEAD and
per-element REFERENCE_SIZE.
Review Comment:
done
--
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]