From: Robert Varga Date: Thu, 24 Mar 2022 20:36:43 +0000 (+0100) Subject: Improve DataNormalizer performance X-Git-Tag: v3.0.0~22 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=netconf.git;a=commitdiff_plain;h=b78c1895a0e08026e85fe370ed018f355ffb1863 Improve DataNormalizer performance We are using ImmutableList.Builder and build() at each step to pass arguments down to checkArgument(). That's wasteful, let's rather pay the cost of a single ImmutableList.copyOf() -- which breaks even at three path arguments. Change-Id: I586761f5e8f8e39f1be3c85bc5e9181c1681e6fd Signed-off-by: Robert Varga --- diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/DataNormalizer.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/DataNormalizer.java index 753b515477..81224b5f36 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/DataNormalizer.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/DataNormalizer.java @@ -10,7 +10,9 @@ package org.opendaylight.netconf.sal.restconf.impl; import static com.google.common.base.Preconditions.checkArgument; import com.google.common.collect.ImmutableList; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; @@ -23,7 +25,7 @@ class DataNormalizer { } YangInstanceIdentifier toNormalized(final YangInstanceIdentifier legacy) { - ImmutableList.Builder normalizedArgs = ImmutableList.builder(); + List normalizedArgs = new ArrayList<>(); DataNormalizationOperation currentOp = operation; Iterator arguments = legacy.getPathArguments().iterator(); @@ -34,7 +36,7 @@ class DataNormalizer { currentOp = currentOp.getChild(legacyArg); checkArgument(currentOp != null, "Legacy Instance Identifier %s is not correct. Normalized Instance Identifier so far %s", - legacy, normalizedArgs.build()); + legacy, normalizedArgs); while (currentOp.isMixin()) { normalizedArgs.add(currentOp.getIdentifier()); currentOp = currentOp.getChild(legacyArg.getNodeType()); @@ -42,10 +44,10 @@ class DataNormalizer { normalizedArgs.add(legacyArg); } } catch (DataNormalizationException e) { - throw new IllegalArgumentException(String.format("Failed to normalize path %s", legacy), e); + throw new IllegalArgumentException("Failed to normalize path " + legacy, e); } - return YangInstanceIdentifier.create(normalizedArgs.build()); + return YangInstanceIdentifier.create(normalizedArgs); } DataNormalizationOperation getOperation(final YangInstanceIdentifier legacy)