Skip to content

[GTK] Cache Tree and TreeItem child counts - #3664

Merged
vogella merged 1 commit into
eclipse-platform:masterfrom
vogella:gtk-tree-item-count-cache
Oct 5, 2026
Merged

vogella merged 1 commit into
eclipse-platform:masterfrom
vogella:gtk-tree-item-count-cache

Conversation

@vogella

@vogella vogella commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

On GTK, Tree.getItemCount() and TreeItem.getItemCount() call gtk_tree_model_iter_n_children, which walks the sibling list on every call. This caches the counts behind a counter that is bumped on every row insertion or removal, so repeated calls become constant time: 40k getItemCount() calls on a 40k-child item drop from 7 to 12 s to about 1 ms, and a reveal-like loop of getItemCount() plus getItem(i) gets 3 to 5 times faster.

This is a partial fix for #882, the same idea as #883: getItem(int) and indexOf still use linear GTK lookups, so loops over all children stay quadratic until children are tracked on the Java side. New tests cover the invalidation on insert, dispose, setItemCount, removeAll and column changes.

gtk_tree_model_iter_n_children walks the sibling list, so every getItemCount() call was linear in the number of children. A counter bumped on each row insertion or removal now guards lazily cached counts, which makes repeated getItemCount() calls constant time.

getItem(int) and indexOf still use linear GTK lookups, so loops over all children remain quadratic.

Part of eclipse-platform#882

Assisted-by: multiple AI agents and layers of automated tooling 🤖
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Test Results

  212 files  ± 0    212 suites  ±0   26m 48s ⏱️ -57s
4 979 tests + 5  4 951 ✅ + 5   28 💤 ±0  0 ❌ ±0 
7 251 runs  +30  7 057 ✅ +30  194 💤 ±0  0 ❌ ±0 

Results for commit 0867537. ± Comparison against base commit 8b89d66.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

All GTK model mutation paths reviewed correctly invalidate the caches, with comprehensive regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Caches GTK Tree child counts to make repeated getItemCount() calls constant time.

Changes:

  • Adds root and per-item child-count caches.
  • Invalidates caches on structural mutations.
  • Adds cache-invalidation tests.
File Description
Tree.java Adds root caching and structural versioning.
TreeItem.java Adds per-item caching and invalidation.
Test_org_eclipse_swt_widgets_Tree.java Tests mutation and virtual-tree scenarios.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@vogella
vogella merged commit e199091 into eclipse-platform:master Oct 5, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants