Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Performance: Map vs List

I've building a tree pagination in JSF1.2 and Richfaces 3.3.2, because I have a lot of tree nodes (something like 80k), and it's slow..

So, as first attempt, I create a HashMap with the page and the list of nodes of the page.

But, the performance isn't good enough...

So I was wondering if is something faster than a HashMap, maybe a List of Lists or something.

Someone have some experience with this? What can I do?

Thanks in advance.


EDIT.

The big problem is that I have to validate permissions of users in the childnodes of the tree. I knew that this is the big problem: this validation is slow, because I have to go inside the nodes, I don't have a good way to know if the user have permission in a 10th level node without iterate all of them. Plus to this, the same three has used in more places... The basic reason for why I was doing this pagination, is that the client side will be much slow, because of the structure generated by richfaces, a lot of tr's and td's, the browser just going crazy with this. So, unfortunatelly, I have to load all the nodes, and paginate just client side, and I need to know what of them is faster to iterate...

Sorry my bad english.

like image 752
caarlos0 Avatar asked Dec 17 '22 02:12

caarlos0


2 Answers

A hash map is the fastest data structure if you want to get all nodes for a page. The list of nodes can be fetched in constant time (O(1)) while with lists the time is O(n) (n=number of pages, faster on sorted lists but never getting near O(1))

What operations on your datastructure are too slow. That's what you have to analyse before you start optimization.

like image 128
Andreas Dolk Avatar answered Dec 18 '22 15:12

Andreas Dolk


It's probably more due to the fact that JSF is a performance pig than a data structure choice. The one attempt I've seen to create a JSF app could be timed with a sundial.

You're making a mistake by guessing about solutions without more knowledge about the root cause. I'd recommend that you profile your app to see where the time is being spent.

like image 29
duffymo Avatar answered Dec 18 '22 17:12

duffymo