`AbstractDataTreeNode.indexOfChild()` is called excessively on large resource tree size
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 重构
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- java
- 领域
- performance
调研方向
从 AbstractDataTreeNode.indexOfChild() 和 DeltaDataTree.lookup() 开始,然后检查链接的 heapdump 分析以及 delta-tree 的父节点遍历。在大型资源树上对 lookup 进行基准测试,并比较提出的优化方向。完成的标准是,所选方案在不改变 lookup 行为的情况下减少报告中的 lookup 热点。
由索引模型根据 Issue 内容生成。
描述
During analysis of two heapdumps shared here the following issue was discovered as a hotspot that can benefit from optimization:
Performance Data
| Metric | WITH transitive | WITHOUT transitive | Ratio |
|---|---|---|---|
| indexOfChild() self time (µs) | 70,405,568 | 35,739,594 | 2.0× |
| DeltaDataTree.lookup() (µs) | 55,328,734 | 24,397,133 | 2.3× |
Description
indexOfChild() performs a binary search on a sorted array of child nodes:
protected int indexOfChild(String localName) {
AbstractDataTreeNode[] nodes = this.children;
int left = 0, right = nodes.length - 1;
while (left <= right) {
int mid = (left + right) / 2;
int compare = localName.compareTo(nodes[mid].name);
// ...
}
return -1;
}
While the binary search itself is O(log n), DeltaDataTree.lookup() calls indexOfChild() at each path segment level:
public DataTreeLookup lookup(IPath key) {
int keyLength = key.segmentCount();
for (DeltaDataTree tree = this; tree != null; tree = tree.parent) {
AbstractDataTreeNode node = tree.rootNode;
for (int i = 0; i < keyLength; i++) {
node = node.childAtOrNull(key.segment(i)); // calls indexOfChild
}
}
}
The delta tree chain (tree.parent) can be deep, and each delta layer requires re-traversing the path from root.
The combined indexOfChild() time (70.4 seconds) represents the single largest CPU consumer in the entire build.
Suggested Fix
- Compact delta chains more aggressively: The parent chain walk is expensive. More frequent immobilization of the delta tree would reduce the number of layers to traverse.
- Cache frequent lookups: If the same resource paths are looked up repeatedly (e.g., project roots, source folders), a small LRU cache on
DeltaDataTree.lookup()could avoid repeated traversals. - Consider hybrid data structure: For nodes with many children (> 100), consider switching from sorted array + binary search to a
HashMap<String, AbstractDataTreeNode>for O(1) child lookup. This is particularly relevant for directories containing many files (e.g., classpath container folders). - Reduce
key.segment(i)overhead: Each call toIPath.segment(i)onPathobjects does array access. Ensure paths are not being reconstructed or re-parsed in hot loops.
- 主要语言
- Java
- 星标
- 165
- 派生
- 174
- 平均合并
- 4 天 7 小时
- 30 天内合并 PR
- 39
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
eclipse-platform/eclipse.platform 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
eclipse-platform/eclipse.platform#3019 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
eclipse-platform/eclipse.platform#2940 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
eclipse-platform/eclipse.platform#2593 · 7 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 3/5 1-2 天 新手友好度 45/100
eclipse-platform/eclipse.platform#3027 ·
维护者通常 1 天内回复
-
JGit runtime logs are spamming debugger console可能已有人在做 @HannesWell 于 8 天前认领。 未关闭bug regression
难度 3/5 1-2 天 新手友好度 56/100
eclipse-platform/eclipse.platform#3022 · 19 条评论 ·
维护者通常 1 天内回复
查看 eclipse-platform/eclipse.platform 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 79/100
checkstyle/checkstyle#22145 ·
维护者通常 1 天内回复
-
rset command throws NPE in ResultsFormat.guessSyntax可能已有人在做 @Ostrzyciel 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
enhancement good first issue help wanted
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
objectionary/eo#9593 ·
维护者通常 1 天内回复
-
release bug
难度 2/5 1-3 小时 新手友好度 68/100
OpenLiberty/open-liberty#36124 ·
维护者通常 1 天内回复