// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.metricsproxy.metric.model;

import java.util.Objects;

/**
 * @author gjoranv
 */
public class MetricId {

    public static final MetricId empty = toMetricId("");
    public final String id;
    private MetricId(String id) { this.id = id; }

    public static MetricId toMetricId(String id) { return new MetricId(id); }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MetricId metricId = (MetricId) o;
        return Objects.equals(id, metricId.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    @Override
    public String toString() {
        return id;
    }

}

@@ -162,79 +162,245 @@
 ort 
-java.util.Objects;%0A%0A/**%0A * @author gjoranv%0A */%0Apublic class MetricId %7B%0A
+com.yahoo.yolean.concurrent.CopyOnWriteHashMap;%0A%0Aimport java.util.Map;%0Aimport java.util.Objects;%0A%0A/**%0A * @author gjoranv%0A */%0Apublic class MetricId %7B%0A%0A    private static final Map%3CString, MetricId%3E dictionary = new CopyOnWriteHashMap%3C%3E();
 %0A   
@@ -582,23 +582,69 @@
 ng id) %7B
- return
+%0A        return dictionary.computeIfAbsent(id, key -%3E
  new Met
@@ -649,20 +649,26 @@
 etricId(
-id);
+key));%0A   
  %7D%0A%0A    

Use a dictionary for metrid ids. There are few unique ones (less than 1k), but many instances.