Browse Source

KAFKA-8736: Streams performance improvement, use isEmpty() rather than size() == 0 (#7164)

Reviewers: A. Sophie Blee-Goldman <sophie@confluent.io>, Matthias J. Sax <matthias@confluent.io>, Guozhang Wang <guozhang@confluent.io>
pull/7169/head
mjarvie 5 years ago committed by Matthias J. Sax
parent
commit
7ebcd50fbf
  1. 4
      streams/src/main/java/org/apache/kafka/streams/state/internals/NamedCache.java
  2. 4
      streams/src/main/java/org/apache/kafka/streams/state/internals/ThreadCache.java

4
streams/src/main/java/org/apache/kafka/streams/state/internals/NamedCache.java

@ -266,6 +266,10 @@ class NamedCache { @@ -266,6 +266,10 @@ class NamedCache {
return cache.size();
}
public boolean isEmpty() {
return cache.isEmpty();
}
synchronized Iterator<Map.Entry<Bytes, LRUNode>> subMapIterator(final Bytes from, final Bytes to) {
return cache.subMap(from, true, to, true).entrySet().iterator();
}

4
streams/src/main/java/org/apache/kafka/streams/state/internals/ThreadCache.java

@ -193,7 +193,7 @@ public class ThreadCache { @@ -193,7 +193,7 @@ public class ThreadCache {
}
return new MemoryLRUCacheBytesIterator(cache.allIterator());
}
public long size() {
long size = 0;
for (final NamedCache cache : caches.values()) {
@ -235,7 +235,7 @@ public class ThreadCache { @@ -235,7 +235,7 @@ public class ThreadCache {
// a put on another cache. So even though the sizeInBytes() is
// still > maxCacheSizeBytes there is nothing to evict from this
// namespaced cache.
if (cache.size() == 0) {
if (cache.isEmpty()) {
return;
}
cache.evict();

Loading…
Cancel
Save