Author: toad
Date: 2007-09-13 19:06:46 +0000 (Thu, 13 Sep 2007)
New Revision: 15146

Modified:
   trunk/freenet/src/freenet/io/comm/MessageCore.java
   trunk/freenet/src/freenet/io/comm/MessageFilter.java
Log:
Significant (hopefully) optimisation to match(): the call to timedOut() was 
occupying the vast majority of this method's CPU time according to profiling on 
meganodes. Only call it when we actually have a match.

Modified: trunk/freenet/src/freenet/io/comm/MessageCore.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageCore.java  2007-09-13 18:40:02 UTC 
(rev 15145)
+++ trunk/freenet/src/freenet/io/comm/MessageCore.java  2007-09-13 19:06:46 UTC 
(rev 15146)
@@ -102,7 +102,7 @@
                synchronized (_filters) {
                        for (ListIterator i = _filters.listIterator(); 
i.hasNext();) {
                                MessageFilter f = (MessageFilter) i.next();
-                               if (f.timedOut()) {
+                               if (f.timedOut(tStart)) {
                                        i.remove();
                                        _timedOutFilters.add(f);
                                } else { // Because _filters are in order of 
timeout, we

Modified: trunk/freenet/src/freenet/io/comm/MessageFilter.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageFilter.java        2007-09-13 
18:40:02 UTC (rev 15145)
+++ trunk/freenet/src/freenet/io/comm/MessageFilter.java        2007-09-13 
19:06:46 UTC (rev 15146)
@@ -166,8 +166,8 @@
        }

        public boolean match(Message m) {
-               if(timedOut()) return false;
                if ((_or != null) && (_or.match(m))) {
+                       if(timedOut(System.currentTimeMillis())) return false;
                        _matched = true;
                        return true;
                }
@@ -188,6 +188,7 @@
                                }
                        }
                }
+               if(timedOut(System.currentTimeMillis())) return false;
                _matched=true;
                return true;
        }
@@ -203,11 +204,11 @@
            return _droppedConnection;
        }

-       public boolean timedOut() {
+       public boolean timedOut(long time) {
                if(_matched) return false;
                if(_callback != null && _callback.shouldTimeout())
                        _timeout = -1; // timeout immediately
-               return _timeout < System.currentTimeMillis();
+               return _timeout < time;
        }

     public Message getMessage() {


Reply via email to