Java性能:映射与列表 [英] Java Performance: Map vs List

查看:41
本文介绍了Java性能:映射与列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在JSF1.2和Richfaces 3.3.2中构建了一个树分页,因为我有很多树节点(大约80k),而且速度很慢..

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..

因此,作为第一次尝试,我创建了一个带有页面和页面节点列表的HashMap.

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...

所以我想知道是否是比HashMap更快的东西,也许是列表列表之类的东西.

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?

谢谢.

编辑.

最大的问题是,我必须在树的子节点中验证用户的权限.我知道这是个大问题:此验证很慢,因为我必须进入节点内部,所以我没有很好的方法来知道用户是否在第10级节点中具有权限而不进行所有操作的迭代.除此之外,这三个在更多地方使用了...我之所以进行这种分页的基本原因是,由于richfaces,许多tr和td所生成的结构,客户端将非常慢,浏览器对此对此感到疯狂.因此,不幸的是,我必须加载所有节点,并且仅对客户端进行分页,并且我需要知道其中哪些迭代速度更快...

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.

推荐答案

如果要获取页面的所有节点,则哈希映射是最快的数据结构.可以按固定时间(O(1))提取节点列表,而使用列表的时间为O(n)(n =页数,在已排序列表上更快,但永远不会接近O(1))

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.

这篇关于Java性能:映射与列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆