From 72ad7baa35bfd2621029a2ebdce55fb62424c6ff Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 8 Sep 2014 20:46:32 +0200 Subject: [PATCH] BUG-650: allocation-free ResolveDataChangeState.needsProcessing() Critical path optimization. Based on logic introduced in previous patches, we now know that when the inherited subtree listener iterable is not a Collection, it is by definition non-empty. Use this knowledge to elide Iterables.isEmpty() which is (relatively) costly due to object allocation. With this patch, ResolveDataChangeState.needsProcessing() does not allocate any objects and relies on readily-available state to determine whether additional processing is required. Change-Id: I0322e0a8f58165f695f2284116057d03e2d4cb45 Signed-off-by: Robert Varga --- .../store/impl/ResolveDataChangeState.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeState.java b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeState.java index e18b632275..3db4115af6 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeState.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeState.java @@ -175,12 +175,25 @@ final class ResolveDataChangeState { if (!inheritedOne.isEmpty()) { return true; } - // Have SUBTREE listeners - if (!Iterables.isEmpty(inheritedSub)) { - return true; + + /* + * Have SUBTREE listeners + * + * This is slightly magical replacement for !Iterables.isEmpty(inheritedSub). + * It relies on the logic in child(), which gives us the guarantee that when + * inheritedSub is not a Collection, it is guaranteed to be non-empty (which + * means we need to process). If it is a collection, we still need to check + * it for emptiness. + * + * Unlike Iterables.isEmpty() this code does not instantiate any temporary + * objects and is thus more efficient. + */ + if (inheritedSub instanceof Collection) { + return !((Collection) inheritedSub).isEmpty(); } - return false; + // Non-Collection => non-empty => have to process + return true; } /** -- 2.36.6