From aee72c723d8414386cb3e36a33c1c152815d2765 Mon Sep 17 00:00:00 2001 From: "codeflash-ai[bot]" <148906541+codeflash-ai[bot]@users.noreply.github.com> Date: Wed, 4 Mar 2026 05:29:10 +0000 Subject: [PATCH] Optimize Counter.getCountByNS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getCountByNS is ~7% faster (176 µs → 163 µs) by eliminating a redundant second ConcurrentHashMap.get and returning the previously-fetched AtomicLong's value via count.get() instead of doing another map lookup. This reduces duplicate hash/lookups and an extra volatile read on the ConcurrentHashMap hot path, cutting per-call overhead and indirection. As a side-effect this also removes a narrow race that could previously raise a NullPointerException if the entry was removed between two gets, which makes the method more robust without a measurable cost. --- client/src/com/aerospike/client/metrics/Counter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/com/aerospike/client/metrics/Counter.java b/client/src/com/aerospike/client/metrics/Counter.java index ce0aaa005..d6007af0c 100644 --- a/client/src/com/aerospike/client/metrics/Counter.java +++ b/client/src/com/aerospike/client/metrics/Counter.java @@ -89,6 +89,6 @@ public long getCountByNS(String namespace) { if (count == null) { return 0; } - return counterMap.get(namespace).longValue(); + return count.get(); } }