Skip to content

Resolve editor and view references without repeated linear scans - #4231

Open
vogella wants to merge 1 commit into
eclipse-platform:masterfrom
vogella:workbench-reference-lookup-cleanup
Open

Resolve editor and view references without repeated linear scans#4231
vogella wants to merge 1 commit into
eclipse-platform:masterfrom
vogella:workbench-reference-lookup-cleanup

Conversation

@vogella

@vogella vogella commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Two cleanups found while profiling the editor open and switch paths, offered as code quality rather than as a speedup.

getOrderedEditorReferences, getSortedEditorReferences and getSortedParts resolved every model element by scanning the reference list from the start and then guarded against duplicates with List.contains, so both parts grew quadratically with the number of open editors and views. They now build an identity map once per call and use a set for the duplicate check, with the resulting order unchanged. ToolItemUpdater.updateContributionItems rescheduled the same runnable through Display.timerExec once per matching item, cancelling and recreating the timer on every iteration although only the last call has any effect, so it is now scheduled once per batch.

Neither change is measurable in the existing tests. I compared both variants with interleaved runs of the editor open, close and switch tests and the difference stayed within the noise, which is expected: the nested scans only matter with many open parts and the redundant timer scheduling only with many contributed tool items, and those tests have neither. Please take them on readability and complexity grounds, not on performance.

Verified with org.eclipse.ui.tests, org.eclipse.e4.ui.tests, org.eclipse.e4.ui.workbench.addons.swt.test and org.eclipse.jface.tests: 1719 tests, no failures.

getOrderedEditorReferences, getSortedEditorReferences and getSortedParts
resolved every model element by scanning the reference list from the
start, and then guarded against duplicates with List.contains, so both
grew quadratically with the number of open editors and views. They now
build an identity map once per call and use a set for the duplicate
check. The resulting order is unchanged.

ToolItemUpdater.updateContributionItems rescheduled the same runnable
through Display.timerExec once per matching item, which cancels and
recreates the timer on every iteration although only the last call has
any effect. Schedule it once per batch instead.

Both are cleanups without a measured runtime effect. The nested scans
only matter with many open parts, and the redundant timer scheduling
only with many contributed tool items, neither of which the current
tests cover.
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Test Results

   858 files  ±0     858 suites  ±0   44m 42s ⏱️ - 7m 8s
 8 130 tests ±0   7 887 ✅ ±0  243 💤 ±0  0 ❌ ±0 
20 292 runs  ±0  19 638 ✅ ±0  654 💤 ±0  0 ❌ ±0 

Results for commit 5ef3902. ± Comparison against base commit f78bd54.

@vogella
vogella marked this pull request as ready for review August 9, 2026 07:30
@vogella
vogella requested a lite review from Copilot August 10, 2026 05:57

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.

Pull request overview

This PR refactors part-reference resolution in the workbench to avoid repeated linear scans when mapping E4 model parts (MPart) to their corresponding EditorReference/ViewReference, and reduces redundant Display.timerExec(...) rescheduling in tool item enablement updates. The changes fit within Eclipse Platform UI’s workbench internals, primarily improving algorithmic complexity and code clarity in hot-ish paths.

Changes:

  • Replace repeated O(n) scans + List.contains(...) duplicate guards with a per-call IdentityHashMap<MPart, …> for lookups and a Set for duplicate filtering, keeping ordering behavior consistent.
  • Optimize placeholder visibility filtering by precomputing rendered placeholders into an identity-based set.
  • Schedule ToolItemUpdater’s delayed runnable once per update batch instead of once per matching item.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPage.java Uses identity maps/sets to resolve editor/view references without repeated scans and quadratic duplicate checks.
bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolItemUpdater.java Avoids redundant timerExec rescheduling by scheduling once per batch when updates are queued.

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

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