In web applications displaying search results in a nice list with all sort of options like paging, sorting and export filters is a common scenario. There are many third party commercial and opensource products addressing the problem. But in very huge product you will always find a custom in house solution to this.
Same is the case in the company I work for. We have our own ListTag to address the problem. It has paging and sorting built in to it. Recently I came across a performance issue regarind a page which was displaying search results from the page. When there were more that 1000 results the page took forever to display. Everyone natuarally was pointing to the database query and there were many solutions proposed.
But I wasn’t convinced, I put in timers to calculate how much time was spent querying the database, populating its results in POJOs and then displaying it to the user. To my surprise the whole time was spent displaying the results to the user. I went inside the ListTag code to find out why was it taking so much time. And what I saw was total horror. All the things from display to sorting was custom built. There were tons of calls writing HTML using response.write using + operator for string concatenation. My first task was to get rid of these. After fixing all this there was significant improvement but still it was taking a lot of time. I found out that the whole time was now spent in the sort function, so naturally the disection was inevitable. I saw several sort fiucntions like IntSort, StringSort, DateSort etc. for sorting things based on the type of the data passed in. Looking at the sorting algorithm I was amazed, It was the basic bubble sort. All the things cleared out and I could explain exactly what was the bottle neck. I immediately replaced bubble sort with QuickSort and the page displayed in a blink.
I am planning on to use DisplayTags (www.displaytag.org) for replacing our custom ListTag so that we don’t have to spent fixing these inhouse solutions. A properly tested solution meant for the problem is a lot better than re-inventing the wheel. Because we dont have to spent time fixing it up and there are updates avaialble for it which take care of the common bugs encountered.