For the more technically-minded, a breakdown of the issues involved here in further optimization:
Your inventory (and storage, and etc) exist in mafia as a LockableListModel. This is the "data model." When you type something into the filter field, that operates on the data model to set each individual element's visibility. Each time something has its visibility changed, it fires an event that causes anything listening to the model to update() itself.
Now, in a list of some thousands, when you type something into the filter field, you can imagine that's a lot of events firing off. Prior to 11046, item manager tables were trying to update after each individual event. Updating involves calling a sorter to sort the rows according to the selected column (default: item name column). More on that later, but suffice to say that doing it thousands of times was unnecessary - now we just fire an event after the data model has been filtered, and the table can update its display once.
Re: sorting. Sorting a list of comparable items is a thing you can take a class or three on. There's a lot of different ways to do it. But essentially there are two salient issues to discuss here.
One, the sorting algorithm. Swingx uses ShuttleSorter, which if you're curious you can inspect yourself
here. The sort() algorithm is too recursive for me to parse at a glance, but it claims n log

worst-case performance. Which is curious since
shuttle sort is generally considered to be O(n^2), not O(n logn). I'll do more research, but I'm not sure why it's not using Java's internal collection sorting, which uses
merge sort.
Two, the comparator. For a list of things to be sorted, every element in said list must implement Comparable - that is, a.compareTo(b) and b.compareTo(a). It is important that we know what class a and b are - 100 compareto( 1000 ) is different than "100" compareto ( "1000" ). Likewise, if strings are mixed in with integers (see: autosell column), everything has to be treated as a string. What all this means is that you have to implement your own Comparator if you want things to be sorted properly. I've done this for two columns - item name and autosell. I need to do this for item name because the text actually has HTML markup in there, and we don't want font color=blah to influence our sorting. The relevant code:
Code:
private final Pattern meatPattern = Pattern.compile( "(-?\\d+) meat" );
private final Pattern itemPattern = Pattern.compile( "(?<=^|>)[^><]+?(?=<|$)" );
protected final Comparator<Object> meatComparator = new Comparator<Object>()
{
public int compare( Object o1, Object o2 )
{
Matcher matcher1 = meatPattern.matcher( o1.toString() );
Matcher matcher2 = meatPattern.matcher( o2.toString() );
if ( !matcher1.find() )
{
return -1;
}
else if ( !matcher2.find() )
{
return 1;
}
// if we're here, both strings are in the format (\d+ meat)
Integer o1val = Integer.valueOf( matcher1.group( 1 ) );
Integer o2val = Integer.valueOf( matcher2.group( 1 ) );
return o1val.compareTo( o2val );
}
};
protected final Comparator<Object> itemComparator = new Comparator<Object>()
{
public int compare( Object o1, Object o2 )
{
Matcher matcher1 = itemPattern.matcher( o1.toString() );
Matcher matcher2 = itemPattern.matcher( o2.toString() );
if ( !matcher1.find() )
{
return -1;
}
else if ( !matcher2.find() )
{
return 1;
}
// if we're here, both matches are the item names stripped of HTML.
String o1val = matcher1.group();
String o2val = matcher2.group();
return o1val.toLowerCase().compareTo( o2val.toLowerCase() );
}
};
Both employ regex, which has performance implications.
What all this means
Sorting a few thousand items takes a while. Sorting integers is faster than sorting strings. Regex slows things down. Some numbers (specific to my system, which is really fast. Also only 1400 items in storage.)
10 trials of sorting "quantity", a purely integer column
Code:
sort took 1569391
sort took 1625041
sort took 1550601
sort took 1619622
sort took 1544458
sort took 1617453
sort took 1554214
sort took 1619260
sort took 1541929
sort took 1625041
10 trials of sorting "autosell", an integer column with 2 regex
Code:
sort took 15966023
sort took 15342314
sort took 16096475
sort took 16538781
sort took 14729807
sort took 16539504
sort took 14815450
sort took 16760295
sort took 15987705
sort took 15286303
10 trials of sorting "item name", a column with 2 regex then a string compare
Code:
sort took 79332161
sort took 15465538
sort took 55983889
sort took 15416754
sort took 58153141
sort took 15402299
sort took 58334182
sort took 15449276
sort took 64393127
sort took 15429763
All numbers in ns, so int sorts took around 1.5 ms, autosell sorts took around 15 ms, and item name sorts bounced between 15 and 60. Note that every other sort is a "descending" sort, so for whatever reason the shuttle algorithm performs poorly on descending string sorts. I'm looking into ways ways to optimize either sort() or the comparator, though I think the sort() algorithm is the better target.