Skip to content

Keep compare borders aligned when line heights change - #3077

Open
tobiasmelcher wants to merge 1 commit into
eclipse-platform:masterfrom
tobiasmelcher:d031119/fix-compare-scroll-geometry
Open

tobiasmelcher wants to merge 1 commit into
eclipse-platform:masterfrom
tobiasmelcher:d031119/fix-compare-scroll-geometry

Conversation

@tobiasmelcher

Copy link
Copy Markdown
Contributor

Fixes #3076.

On macOS, scrolling or using Next Change can make SWT discover a taller font for a character and increase the text line height. Compare kept using its earlier cached heights, so the change borders and connecting lines no longer matched the text. The cache responsible for these stale positions was introduced in #1492 (commit 80fd47a) to avoid freezes when comparing large files with line spacing enabled. This change preserves that performance benefit rather than removing the cache.

Each viewer still caches the height of each line. Before drawing or handling a mouse hit, Compare checks the font, base line height, spacing and line count, then compares the total height of the already-cached first part of the file with SWT's current position for its end. A mismatch discards the stale cache. Document, text styling and zoom changes also discard it. The check does not fill the cache for the entire file. Where the cache is not suitable, including wrapped text and zero global line spacing, drawing and mouse hit detection use SWT's current line positions. SWT itself is unchanged.

The local macOS geometry benchmark used 100,000 lines, 50-pixel line spacing and 200 change positions. With a warmed cache, the original approach took about 3.75 ms and the chosen checkpoint approach about 3.84 ms: roughly 0.09 ms extra, or 2.4%. Removing Compare's cache and requesting every position directly from SWT took about 16.9 ms, around 4.5 times the original. Keeping the cache but checking the indentation of every visited line took about 24.6 ms, around 6.6 times the original. These are geometry-only timings, not timings for a complete editor repaint.

A whole-document end-position check was also considered: it took about 0.1 ms warm and 1.1 ms on its first query in the 100,000-line measurement, but can request layout beyond the part of the file needed for drawing. Checking only the populated cache prefix avoids that extra work. Initial cache filling was already expensive in the old approach, about 4.58 seconds with 50-pixel spacing and about 63 seconds with a per-line spacing provider. SWT has no dedicated public notification for these line-height changes, so relying only on repaint, resize or zoom notifications would not reliably identify a stale cache.

Preserve the per-viewer line-height cache and discard it when widget metrics or the cached prefix height no longer match SWT. Use current SWT line positions where caching is unsuitable so borders, connectors and mouse hit detection stay aligned after scrolling.

Fixes eclipse-platform#3076
@tobiasmelcher
tobiasmelcher force-pushed the d031119/fix-compare-scroll-geometry branch from 2811a31 to 51a28ab Compare November 16, 2026 14:13
@vogella

vogella commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

In case you need an extra reviewer for a critical change in the new compare, please ping me in the corresponding PR.

@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

In case you need an extra reviewer for a critical change in the new compare, please ping me in the corresponding PR.

Thanks for the offer, @vogella! This fix concerns the traditional two-way compare rather than the new unified diff view. It addresses a cache invalidation problem observed on macOS in the line-height caching introduced by #1492, while preserving its performance benefits. Would you still be interested in reviewing it?

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

    54 files  ±0      54 suites  ±0   36m 44s ⏱️ - 1m 5s
 5 022 tests ±0   5 000 ✅ ±0   22 💤 ±0  0 ❌ ±0 
12 957 runs  ±0  12 803 ✅ ±0  154 💤 ±0  0 ❌ ±0 

Results for commit 51a28ab. ± Comparison against base commit 30dafa8.

@vogella

vogella commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

I reproduced the misaligned borders on macOS without the change: after scrolling into lines with emoji and back up, the boxes sat several lines away from the change. With this PR they stay on the changed lines.

Feedback:

  • TextMergeViewerGeometryTest and TextMergeViewerScrollRegressionTest are not in AllTeamUITests, so CI does not run them (test count ±0). org.eclipse.compare.tests, next to TextMergeViewerTest, might be a better home for them.
  • Both new test files lack the license header.
  • validateLineHeightCache checks !cache.matches(textWidget) twice.
  • When the check finds a stale cache it drops the whole cache. Would it be worth dropping only the entries from the first mismatching line onward, so a large file doesn't refill completely?

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.

macOS: two-way Java compare diff borders and connectors become misaligned during navigation and scrolling

2 participants