openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1830456 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/event/NotificationManager.java main/java/org/apache/webbeans/util/AnnotationUtil.java test/java/org/apache/webbeans/test/events/observer/EventTest.java
Date Sat, 28 Apr 2018 15:37:17 GMT
Author: struberg
Date: Sat Apr 28 15:37:17 2018
New Revision: 1830456

URL: http://svn.apache.org/viewvc?rev=1830456&view=rev
Log:
OWB-1243 after filterByTypes we don't need Set as there are no duplicates anymore

So we can switch to ArrayList which is much faster

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/observer/EventTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java?rev=1830456&r1=1830455&r2=1830456&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
Sat Apr 28 15:37:17 2018
@@ -220,10 +220,10 @@ public final class NotificationManager
     }
 
 
-    public <T> Set<ObserverMethod<? super T>> resolveObservers(T event,
EventMetadataImpl metadata, boolean isLifecycleEvent)
+    public <T> Collection<ObserverMethod<? super T>> resolveObservers(T
event, EventMetadataImpl metadata, boolean isLifecycleEvent)
     {
         Type eventType = metadata.validatedType();
-        Set<ObserverMethod<? super T>> observersMethods = filterByType(event,
eventType, isLifecycleEvent);
+        Collection<ObserverMethod<? super T>> observersMethods = filterByType(event,
eventType, isLifecycleEvent);
 
         observersMethods = filterByQualifiers(observersMethods, metadata.getQualifiers());
 
@@ -242,9 +242,9 @@ public final class NotificationManager
         return observersMethods;
     }
 
-    private <T> Set<ObserverMethod<? super T>> filterByWithAnnotations(Set<ObserverMethod<?
super T>> observersMethods, AnnotatedType annotatedType)
+    private <T> Collection<ObserverMethod<? super T>> filterByWithAnnotations(Collection<ObserverMethod<?
super T>> observersMethods, AnnotatedType annotatedType)
     {
-        Set<ObserverMethod<? super T>> observerMethodsWithAnnotations = new HashSet<>();
+        List<ObserverMethod<? super T>> observerMethodsWithAnnotations = new
ArrayList<>();
 
         for (ObserverMethod<? super T> observerMethod : observersMethods)
         {
@@ -618,9 +618,9 @@ public final class NotificationManager
      * filter out all {@code ObserverMethod}s which do not fit the given
      * qualifiers.
      */
-    private <T> Set<ObserverMethod<? super T>> filterByQualifiers(Set<ObserverMethod<?
super T>> observers, Set<Annotation> eventQualifiers)
+    private <T> Collection<ObserverMethod<? super T>> filterByQualifiers(Collection<ObserverMethod<?
super T>> observers, Set<Annotation> eventQualifiers)
     {
-        Set<ObserverMethod<? super T>> matching = new HashSet<>();
+        List<ObserverMethod<? super T>> matching = new ArrayList<>(observers.size());
 
         search: for (ObserverMethod<? super T> ob : observers)
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java?rev=1830456&r1=1830455&r2=1830456&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
Sat Apr 28 15:37:17 2018
@@ -213,6 +213,11 @@ public final class AnnotationUtil
             return false;
         }
 
+        if (annotation1 == annotation2)
+        {
+            return true;
+        }
+
         Class<? extends Annotation> qualifier1AnnotationType
                 = annotation1.annotationType();
 

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/observer/EventTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/observer/EventTest.java?rev=1830456&r1=1830455&r2=1830456&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/observer/EventTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/observer/EventTest.java
Sat Apr 28 15:37:17 2018
@@ -20,9 +20,12 @@ package org.apache.webbeans.test.events.
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Logger;
 
 import org.apache.webbeans.test.AbstractUnitTest;
 import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class EventTest extends AbstractUnitTest {
@@ -148,6 +151,33 @@ public class EventTest extends AbstractU
         Assert.assertEquals("Superclass", testEvent.getCalledObservers().iterator().next());
 
         shutDownContainer();
+    }
+
+    @Test
+    @Ignore("only for manual performance testing and debugging")
+    public void testEventPerformance()
+    {
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(Painter.class);
+        startContainer(beanClasses, null);
+
+        final Orange orange = new Orange();
+
+        Logger.getLogger(EventTest.class.getName()).info("Starting performance test");
+
+        long start = System.nanoTime();
+        for (int i = 0; i < 5_000_000; i++)
+        {
+            getBeanManager().fireEvent(orange);
+        }
+
+        long end = System.nanoTime();
 
+        Logger.getLogger(EventTest.class.getName())
+            .info("firing Events took " + TimeUnit.NANOSECONDS.toMillis(end - start));
+
+        shutDownContainer();
     }
+
+
 }



Mime
View raw message