You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/11/06 07:52:47 UTC

[dubbo] branch 3.0 updated: [3.0] Reduce array creation when routing (#9219)

This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new 57ab318  [3.0] Reduce array creation when routing (#9219)
57ab318 is described below

commit 57ab318ee8be9aeb84ccfbae7a3ade1f4b0c5e27
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Sat Nov 6 15:52:34 2021 +0800

    [3.0] Reduce array creation when routing (#9219)
    
    * [3.0] Reduce array creation when routing
    
    * fix ut
    
    * fix ut
---
 .../main/java/org/apache/dubbo/rpc/cluster/RouterChain.java   |  3 +--
 .../org/apache/dubbo/rpc/cluster/router/state/BitList.java    | 11 +++++------
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java
index 5cae5f8..0522ace 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java
@@ -315,13 +315,12 @@ public class RouterChain<T> {
             return;
         }
         AddrCache<T> origin = cache.get();
-        List<Invoker<T>> copyInvokers = new ArrayList<>(this.invokers);
         AddrCache<T> newCache = new AddrCache<T>();
         Map<String, RouterCache<T>> routerCacheMap = new HashMap<>((int) (stateRouters.size() / 0.75f) + 1);
         newCache.setInvokers(invokers);
         for (StateRouter stateRouter : stateRouters) {
             try {
-                RouterCache routerCache = poolRouter(stateRouter, origin, copyInvokers, notify);
+                RouterCache routerCache = poolRouter(stateRouter, origin, invokers, notify);
                 //file cache
                 routerCacheMap.put(stateRouter.getName(), routerCache);
             } catch (Throwable t) {
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/BitList.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/BitList.java
index 09f250d..359e2ed 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/BitList.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/BitList.java
@@ -19,7 +19,6 @@ package org.apache.dubbo.rpc.cluster.router.state;
 import org.apache.dubbo.common.utils.CollectionUtils;
 
 import java.util.AbstractList;
-import java.util.ArrayList;
 import java.util.BitSet;
 import java.util.Collections;
 import java.util.Iterator;
@@ -52,7 +51,7 @@ import java.util.NoSuchElementException;
  */
 public class BitList<E> extends AbstractList<E> {
     private final BitSet rootSet;
-    private final List<E> originList;
+    private volatile List<E> originList;
     private final static BitList emptyList = new BitList(Collections.emptyList());
     private volatile List<E> tailList = null;
 
@@ -61,7 +60,7 @@ public class BitList<E> extends AbstractList<E> {
     }
 
     public BitList(List<E> originList, boolean empty) {
-        this.originList = new ArrayList<>(originList);
+        this.originList = originList;
         this.rootSet = new BitSet();
         if (!empty) {
             this.rootSet.set(0, originList.size());
@@ -69,7 +68,7 @@ public class BitList<E> extends AbstractList<E> {
     }
 
     public BitList(List<E> originList, BitSet rootSet, List<E> tailList) {
-        this.originList = new ArrayList<>(originList);
+        this.originList = originList;
         this.rootSet = rootSet;
         this.tailList = tailList;
     }
@@ -175,9 +174,9 @@ public class BitList<E> extends AbstractList<E> {
     public void clear() {
         rootSet.clear();
         // to remove references
-        originList.clear();
+        originList = Collections.emptyList();
         if (CollectionUtils.isNotEmpty(tailList)) {
-            tailList.clear();
+            tailList = null;
         }
     }