Skip to content

Prevent repaint loops when code minings share a host character - #4588

Open
tobiasmelcher wants to merge 1 commit into
eclipse-platform:masterfrom
tobiasmelcher:fix-shared-code-mining-repaint-loop
Open

tobiasmelcher wants to merge 1 commit into
eclipse-platform:masterfrom
tobiasmelcher:fix-shared-code-mining-repaint-loop

Conversation

@tobiasmelcher

@tobiasmelcher tobiasmelcher commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Saving a Java editor froze Eclipse while Copilot was showing several long code predictions. The editor kept repainting itself and the save never finished.

Thread dumps

I took ten thread dumps of the frozen IDE. There was no deadlock. The UI thread used almost a full CPU core and was always busy painting the editor. It was running the event loop of the progress dialog that organize imports on save had opened. The dialog's background thread had already finished its work. It was waiting in the empty Display.syncExec that ends the operation:

"main" RUNNABLE
  AbstractCodeMining.draw
  InlinedAnnotationDrawingStrategy.drawAsLeftOf1stCharacter
  AnnotationPainter.paintControl
  Composite.WM_PAINT
  Display.readAndDispatch
  ModalContext$ModalContextThread.block
  ...
  CleanUpPostSaveListener.saved
  CompilationUnitEditor.doSave

"ModalContext" WAITING
  Display.syncExec
  ModalContext$ModalContextThread.run(ModalContext.java:141)

On Windows, SWT runs a syncExec only when no other events are waiting. Because the editor always had a new paint pending, the save could not complete.

Cause

A code mining makes room for itself by widening a character in the editor. Two minings at different positions can choose the same character, for example one at the start of a line and one right after it. Each mining sets that character's width to fit only itself, and every width change triggers another paint:

flowchart TD
    P[Paint editor] --> A[Mining A sets width to 620 px]
    A --> B[Mining B sets width to 930 px]
    B --> C{Width changed?}
    C -- "yes, every time" --> P
    C -. never .-> S[Save completes]
Loading

The width never settles, so the editor never stops painting. The two minings were also drawn on top of each other.

Fix

Minings that share a character are now laid out together. The character gets room for all of them, and each mining is drawn in its own part of that space. Every mining asks for the same width, so painting stops after the first paint:

flowchart TD
    P[Paint editor] --> A[Minings A and B set width to 620 + 930 px]
    A --> C{Width changed?}
    C -- "first paint only" --> P
    C -- no --> S[Save completes]
Loading

When a mining is removed, the extra space goes away with it.

The new CodeMiningRepaintTest reproduces the problem with two long minings on a shared character. Without the fix, the editor repaints several hundred times per second. With the fix, it stops repainting.

Reserve the combined width of annotations sharing a glyph and draw each mining in its own space. Keep host-character measurement consistent and cover sustained repainting with a bounded UI regression test.
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

   867 files  ± 0     867 suites  ±0   54m 40s ⏱️ - 5m 27s
 8 574 tests + 7   8 334 ✅ + 7  240 💤 ±0  0 ❌ ±0 
21 594 runs  +21  20 921 ✅ +21  673 💤 ±0  0 ❌ ±0 

Results for commit 89d6ba2. ± Comparison against base commit 50268ca.

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.

1 participant