A Tale of Compromises in Graphical User Design
Join the DZone community and get the full member experience.Join For Free
i recently received an alarming bug report about the testng eclipse plug-in :
i’m talking about testng plugin for eclipse and its performance. since some time this plugin contains new feature – searching already finished tests. (just “search: ” with a field).
performing this search makes that my eclipse does not response for minutes. after all i can see as a result – all historical run tests (according to my search request).
a bug that would cause eclipse to be unresponsive for minutes is certainly unacceptable, so i tried to dig into this problem quickly. however, i was still not quite sure what this user was doing, and since i use and i work on the plug-in on a regular basis, the problem have been happening under some very specific and unusual circumstances. a few emails later, i received the following clarification:
yes, i’m talking about the search box and filtering.
‘historical data” means all collected test results. in case i don’t restart eclipse for weeks and start million tests (via providers) performance plays here important role.
in fact i don’t need the search box feature. simply today i filled it up by mistake and lost half an hour… first to find, second to remove from the box…
i have to say i laughed when i read “i filled it by mistake and lost a half hour”. okay, maybe not very funny from this user’s stand point, but funny because i can see how having a million test instances could cause the plug-in to become unresponsive.
the problem is caused by the “search filter”, a feature that appeared in the plug-in a few months ago:
when you type characters in this text box, the results displayed in the tree get filtered and only the nodes that match the text are shown, a functionality that is very convenient when you want to inspect the results of a specific test.
this poor user created a test run with one million test instances, accidentally typed a letter in the search box and then the plug-in diligently went through the million nodes, retaining only those that contain this letter. obviously, deleting this character will cause the exact same thing to happen, except that the entirety of the test suite will be restored in the tree view.
this code is fairly naive and not really optimized to account for the creation of a million treeitems, so i wasn’t really surprised to hear that doing so would cause eclipse to become unresponsive for a while. after all, the addition of these swt objects has to be made on the event dispatch thread at some point, and whether you add them one by one or in bulk (which is what the plug-in is doing), it’s pretty much guaranteed that the dispatch thread will get severely hogged.
it’s a pretty simple problem with a few obvious solutions, the hard part is finding out the best course of action.
my first thought at trimming down the solution space was to decide that a test result featuring millions of objects was an unusual case and that optimizing this part of the code should therefore not be my priority. but just for the sake of argument, i explored several ways of doing so and i came up with various ideas, among which doing some precaching of subwords (for example, so i can match three letter words to nodes very quickly) or by virtualizing the tree. i’m sure there are plenty of other techniques available and i’m definitely interested in hearing about them.
but for now, i decided to take a lighter approach, so i made two changes:
1) when i detect that the tree contains more than a certain number of nodes, i configure the text box not to start filtering until it has at least three characters. this addresses the problem of accidentally typing a letter in the box, and it also guarantees that when the filtering is triggered, it will match fewer nodes (since these will have to match three letters instead of just one). obviously, the code sill has to go through the million nodes.
this looks simple enough but i couldn’t help trying to devise clever ways of actually calibrating these numbers: when should this behavior be triggered? 1000 nodes? 10,000 nodes? also, should the minimum number of characters be a function of that number? for example, require two characters for 1000 nodes but three for 10,000 nodes? how about using a log in base 1000 to create these pairs of values? or should the base of the log be 50?
2) i added a new “clear results” icon to the toolbar:
clicking it wipes the results displayed in all the panes, which guarantees that typing text in the search filter will do nothing (the search text box actually gets disabled).
the only concern i have with this approach is that users might get confused to see that sometimes, the search filter will activate with one character and other times, it requires three. they might even think that the search filter is broken if nothing happens after typing two characters.
you can work around this problem by providing a tool tip to the text box or, better, display a helpful text tip in a greyed out font inside the text box itself, saying something like “[type at least three characters to search]“ .
i found it interesting how such a simple problem can offer so many different avenues to solve it and how each one comes with benefits and costs that need to be carefully weighed. i’m hoping to have struck a correct balance with the current approach, one which solves the problem at hand without impacting most of the regular users too adversely.
Opinions expressed by DZone contributors are their own.