From ec31847d9340b16021ed4f8d207a35304e053a32 Mon Sep 17 00:00:00 2001 From: JayajP Date: Tue, 16 Apr 2024 14:02:48 -0700 Subject: [PATCH] Skip calling Compute in RemoveSafeDeltaCounterCell if value exists (#30913) * Skip calling Compute in RemoveSafeDeltaCounterCell if value already exists * Address comments --- .../worker/RemoveSafeDeltaCounterCell.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/RemoveSafeDeltaCounterCell.java b/runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/RemoveSafeDeltaCounterCell.java index cf68de42acb2..657aad420669 100644 --- a/runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/RemoveSafeDeltaCounterCell.java +++ b/runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/RemoveSafeDeltaCounterCell.java @@ -62,15 +62,12 @@ public void reset() { @Override public void inc(long n) { - countersMap.compute( - metricName, - (name, value) -> { - if (value == null) { - return new AtomicLong(n); - } - value.addAndGet(n); - return value; - }); + AtomicLong val = countersMap.get(metricName); + if (val != null) { + val.getAndAdd(n); + return; + } + countersMap.computeIfAbsent(metricName, name -> new AtomicLong()).getAndAdd(n); } @Override