File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes Perfomance Issue with Tree Loading (using ArrayList) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Perfomance Issue with Tree Loading (using ArrayList)" Watch "Perfomance Issue with Tree Loading (using ArrayList)" New topic
Author

Perfomance Issue with Tree Loading (using ArrayList)

amit bose
Greenhorn

Joined: Apr 01, 2005
Posts: 25
Hi All,

I have an application wherein we have 2 frames.

Left frame has a tree-like structure and the Right frame has the details of the selected node (just as in windows folders)

On the right frame, apart from the details ,there are a set of buttons which are of two kinds:
(a)Buttons used to manipulate tree nodes itself like 'Add Node', 'Delete
Node'(Tree state changes) Basically tree must be refreshed from DB to
show the changed state
(b)Buttons used to manipulate the node details (Tree state remains the same)

Issues:
In case of say 30 nodes its fine but beyond that if the nodes are say 100 in number, then the page takes a lot of time to load(more than 8 seconds).

Also, when the tree refresh happens (in case of (a) above) it's even more slow.....(more than 12 seconds)

Right now I am using an arrayList for node population(We chose arrayList as out of about 18 functionalities, in only 3 - add/move/delete node, the tree state gets refreshed, otherwise for rest of the 15 functionalities
the tree state remains the same)

Is there a better collection that may render better performance ?
How may I address the performance issue?

Regards,
Amit
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
How did you allocate the memory for the ArrayList? Did you try allocating a big chunk upfront?. How exactly do you process Add/Delete of nodes? If you are processing from scratch then you can think about operations like retaining the existing ArrayList minus deleted node or adding the new node. If you can paste the code it will help..
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
ArrayList operations are VERY fast, I'm sure your problem lies elsewhere. You might want to do some profiling, for instance with JAmon - (free).
Bill
amit bose
Greenhorn

Joined: Apr 01, 2005
Posts: 25
I actually did not allocate any memory before populating the ArrayList.

I would do the following:
Given that I would have about 500 elements in the ArrayList,
I would require to initialize with 500 elements before populating arrayList.

Please let me know if any other tuning is possible?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
To use the Texas vernacular "you are barking up the wrong tree" - any process taking more than a few milliseconds is NOT being held up by the operation of ArrayList functions.
Perhaps your code is redrawing the screen after every addition - that can chew up some time, but my money is on ANY database operation.
RIGHT NOW, before doing anything else! Go get JAMon and instrument your program to see whats really taking the time.
Bill
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Please don't post the same question to more than one forum; see our explanation here. I've deleted the other copy of this thread in JiG(Advanced.)

As Mr. Brogden says, go figure out where the time is actually going, before you try to optimize! It's silly to waste time speculating when you could instead be measuring.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Perfomance Issue with Tree Loading (using ArrayList)