Hi all,
During a smack’s profiling task it emerged a bottleneck managing the roster items and precisly the getEntry(String) method.
I guess the cycle that scroll the entries (roster items) slow down the process, to improve such point I tried to change the algorithm for roster items managing.
I replace the entries type of CopyOnWriteArrayList<RosterEntry> with a TreeMap<String,RosterEntry>, the key is the username, the value the roster entry.
In this way the list is ordered and the research of a specific entry is fast:
public RosterEntry getEntry(String user) {
if (user == null) {
return null;
}
return entries.get(user.toLowerCase());
}
instead of:
public RosterEntry getEntry(String user) {
if (user == null) {
return null;
}
String userLowerCase = user.toLowerCase();
for (RosterEntry entry : entries) {
if (entry.getUser().equals(userLowerCase)) {
return entry;
}
}
return null;
}
This enhancement speed up the process and our applications over smack library.
What do you think about this update? I attach the source class.
Thanks.
Giancarlo Frison
Roster.java (37539 Bytes)