summaryrefslogtreecommitdiffstats
path: root/component
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-10-12 08:55:19 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2022-10-12 09:12:05 +0200
commit1cb581c8873591316fd20927931e24efc3e5837d (patch)
tree878d779e55224791e199a2ca4326d8983aca8fa9 /component
parent09489728d0912761649106f00d7837281b272a76 (diff)
- Use a common scratchpad for serializing the different parts of the query.
- Use a threadlocal for the scratchpad. This avoids costly resizing, or initialiing too large buffer for every query. Using a thread local is fine now that we limit the number of search threads to a reasonable number = #cores * 2.
Diffstat (limited to 'component')
-rw-r--r--component/src/main/java/com/yahoo/component/ComponentId.java19
1 files changed, 5 insertions, 14 deletions
diff --git a/component/src/main/java/com/yahoo/component/ComponentId.java b/component/src/main/java/com/yahoo/component/ComponentId.java
index 7320d24b57c..b869202d3c7 100644
--- a/component/src/main/java/com/yahoo/component/ComponentId.java
+++ b/component/src/main/java/com/yahoo/component/ComponentId.java
@@ -16,19 +16,11 @@ public final class ComponentId implements Comparable<ComponentId> {
private final Spec<Version> spec;
private final boolean anonymous;
- private static AtomicInteger threadIdCounter = new AtomicInteger(0);
+ private static final AtomicInteger threadIdCounter = new AtomicInteger(0);
- private static ThreadLocal<Counter> threadLocalUniqueId = new ThreadLocal<Counter>() {
- @Override protected Counter initialValue() {
- return new Counter();
- }
- };
+ private static final ThreadLocal<Counter> threadLocalUniqueId = ThreadLocal.withInitial(Counter::new);
- private static ThreadLocal<String> threadId = new ThreadLocal<String>() {
- @Override protected String initialValue() {
- return new String("_" + threadIdCounter.getAndIncrement() + "_");
- }
- };
+ private static final ThreadLocal<String> threadId = ThreadLocal.withInitial(() -> "_" + threadIdCounter.getAndIncrement() + "_");
/** Precomputed string value */
private final String stringValue;
@@ -97,9 +89,8 @@ public final class ComponentId implements Comparable<ComponentId> {
@Override
public boolean equals(Object o) {
if (o == this) return true;
- if ( ! (o instanceof ComponentId)) return false;
+ if ( ! (o instanceof ComponentId c)) return false;
- ComponentId c = (ComponentId) o;
if (isAnonymous() || c.isAnonymous()) // TODO: Stop doing this
return false;
@@ -221,7 +212,7 @@ public final class ComponentId implements Comparable<ComponentId> {
return new ComponentId(splitter.name, Version.fromString(splitter.version), splitter.namespace, true);
}
- private final class VersionHandler implements Spec.VersionHandler<Version> {
+ private static final class VersionHandler implements Spec.VersionHandler<Version> {
@Override
public Version emptyVersion() {