Skip to content

Commit eaed0f3

Browse files
committed
Add TODOs with notes for optimization and commented out logging code.
To evaluate the logs this produces: grep -Eo or-match.* ~/Freenet/logs/freenet-latest.log | \ sort | uniq -c | sort -h \ > misordered-MessageFilter-or-matches.log cat misordered-MessageFilter-or-matches.log this produces a list of MessageFilters with the frequency for pairs where the first is the one that did not match and the second is the filter that did match.
1 parent e0e5f24 commit eaed0f3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/freenet/io/comm/MessageFilter.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ private MessageFilter() {
6565
}
6666

6767
public static MessageFilter create() {
68+
// TODO: move to a builder so we can get rid of the synchronized(_fields) in match,
69+
// the most expensive method in all of fred.
70+
// TODO: move source and type into create to get rid of the null-checks in match.
6871
return new MessageFilter();
6972
}
7073

@@ -178,6 +181,8 @@ public MessageFilter setField(String fieldName, Object fieldValue) {
178181
* Modifies the filter so that it returns true if either it or the filter in the argument returns true.
179182
* Multiple combinations must be nested: such as filter1.or(filter2.or(filter3))).
180183
* filter2 will be checked before filter1, so make sure to add the most common last.
184+
* TODO: change the ordering in match: A.or(B) should first check A, like in A || B.
185+
* TODO: ensure for all usages of or(...) that the most likely package is checked first.
181186
* @return reference to this, the modified filter.
182187
*/
183188
public MessageFilter or(MessageFilter or) {
@@ -213,8 +218,9 @@ public MATCHED match(Message m, long now) {
213218
public MATCHED match(Message m, boolean noTimeout, long now) {
214219
if(_or != null) {
215220
MATCHED matched = _or.match(m, noTimeout, now);
216-
if(matched != MATCHED.NONE)
221+
if(matched != MATCHED.NONE) {
217222
return matched; // Filter is matched once only. That includes timeouts.
223+
}
218224
}
219225

220226
final MATCHED resultNoMatch = _timeout < now ? MATCHED.TIMED_OUT : MATCHED.NONE;
@@ -242,6 +248,10 @@ public MATCHED match(Message m, boolean noTimeout, long now) {
242248
if(logMINOR) Logger.minor(this, "Matched but timed out: "+this);
243249
return MATCHED.TIMED_OUT_AND_MATCHED;
244250
}
251+
// debugging output to optimize ordering of or-combined MessageFilters
252+
// if (_or != null) {
253+
// Logger.error(this, "Filter or-match failed: or: " + _or._type.getName() + " this: " + this._type.getName());
254+
// }
245255
return MATCHED.MATCHED;
246256
}
247257

src/freenet/node/PeerMessageQueue.java

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* @author Matthew Toseland <[email protected]> (0xE43DA450)
2121
*/
2222
public class PeerMessageQueue {
23+
// TODO: check whether we can use a standard PriorityBlockingQueue (since Java 8)
24+
// instead of our own DoublyLinkedList implementation.
2325

2426
private static volatile boolean logMINOR;
2527
private static volatile boolean logDEBUG;

0 commit comments

Comments
 (0)