[ 
https://issues.apache.org/jira/browse/ARTEMIS-4814?focusedWorklogId=923164&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-923164
 ]

ASF GitHub Bot logged work on ARTEMIS-4814:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 12/Jun/24 17:58
            Start Date: 12/Jun/24 17:58
    Worklog Time Spent: 10m 
      Work Description: joshb1050 commented on code in PR #4972:
URL: https://github.com/apache/activemq-artemis/pull/4972#discussion_r1636884171


##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/SimpleAddressManager.java:
##########
@@ -160,15 +172,7 @@ public Collection<Binding> getMatchingBindings(final 
SimpleString address) throw
    @Override
    public Collection<Binding> getDirectBindings(final SimpleString address) 
throws Exception {
       SimpleString realAddress = CompositeAddress.extractAddressName(address);
-      Collection<Binding> bindings = new ArrayList<>();
-
-      nameMap.forEach((bindingUniqueName, bindingAddressPair) -> {
-         if (bindingAddressPair.getA().getAddress().equals(realAddress)) {
-            bindings.add(bindingAddressPair.getA());
-         }
-      });
-
-      return bindings;
+      return new ArrayList<>(directBindingMap.getOrDefault(realAddress, 
Collections.emptyList()));

Review Comment:
   It's a copy operation, and works efficiently internally (at least in JDK 
17). We could do a null check instead and return a new list if null, but this 
has to be a defensive copy since the tests will otherwise fail. 
   ```
       public ArrayList(Collection<? extends E> c) {
           Object[] a = c.toArray();
           if ((size = a.length) != 0) {
               if (c.getClass() == ArrayList.class) {
                   elementData = a;
               } else {
                   elementData = Arrays.copyOf(a, size, Object[].class);
               }
           } else {
               // replace with empty array.
               elementData = EMPTY_ELEMENTDATA;
           }
       }
   ```





Issue Time Tracking
-------------------

    Worklog Id:     (was: 923164)
    Time Spent: 1h 10m  (was: 1h)

> Remove linear iteration to get direct bindings
> ----------------------------------------------
>
>                 Key: ARTEMIS-4814
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-4814
>             Project: ActiveMQ Artemis
>          Issue Type: Task
>          Components: Broker
>            Reporter: Josh Byster
>            Priority: Minor
>          Time Spent: 1h 10m
>  Remaining Estimate: 0h
>
> Currently, with 500K+ queues, the cleanup step of {{TempQueueCleanerUpper}} 
> requires invoking {{WildcardAddressManager#getDirectBindings}}, which is O(k) 
> in the number of queues.
> From method profiling, this can consume up to 95% of our CPU time when 
> needing to clean up many of these. 
> It would be nice to make this more efficient, which shouldn't be difficult 
> given the iteration just does a simple equality check.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to