Eliminate ReplicaStatementContext.haveRef 09/94009/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 2 Dec 2020 14:10:51 +0000 (15:10 +0100)
committerRobert Varga <nite@hq.sk>
Wed, 2 Dec 2020 15:02:17 +0000 (15:02 +0000)
This is a very costly boolean, costing us on alignment in the range
of 4-16 bytes. As it turns out we can reuse the boolean used for
fullyDefined(), so do that and reduce instance size.

JIRA: YANGTOOLS-1184
Change-Id: I59a6227c1715549472358e3ca8f003d800377322
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReplicaStatementContext.java

index a602aebce7bfdd01b5748c023d0b0db3e9960f58..b371a067447893b18662223174a9ea5372f21866 100644 (file)
@@ -433,7 +433,8 @@ abstract class ReactorStmtCtx<A, D extends DeclaredStatement<A>, E extends Effec
         return false;
     }
 
-    // These two exists only due to memory optimization, should live in AbstractResumedStatement
+    // These two exists only due to memory optimization, should live in AbstractResumedStatement. We are also reusing
+    // this for ReplicaStatementContext's refcount tracking.
     final boolean fullyDefined() {
         return fullyDefined;
     }
index 8038d92f2eb2b35c00e6fcf93a4239a669f22b33..9a9360f8fc40bbc7a04bdcf40c99474183180d80 100644 (file)
@@ -20,8 +20,6 @@ import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * A replica of a different statement. It does not allow modification, but produces an effective statement from a
@@ -29,23 +27,18 @@ import org.slf4j.LoggerFactory;
  */
 final class ReplicaStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
         extends StatementContextBase<A, D, E> {
-    private static final Logger LOG = LoggerFactory.getLogger(ReplicaStatementContext.class);
-
     private final StatementContextBase<?, ?, ?> parent;
     private final StatementContextBase<A, D, E> source;
 
-    private final boolean haveRef;
-
     ReplicaStatementContext(final StatementContextBase<?, ?, ?> parent, final StatementContextBase<A, D, E> source) {
         super(source);
         this.parent = requireNonNull(parent);
         this.source = requireNonNull(source);
         if (source.isSupportedToBuildEffective()) {
             source.incRef();
-            haveRef = true;
+            setFullyDefined();
         } else {
             setIsSupportedToBuildEffective(false);
-            haveRef = false;
         }
     }
 
@@ -106,7 +99,7 @@ final class ReplicaStatementContext<A, D extends DeclaredStatement<A>, E extends
 
     @Override
     int sweepSubstatements() {
-        if (haveRef) {
+        if (fullyDefined()) {
             source.decRef();
         }
         return 0;