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

@tobiasmelcher tobiasmelcher commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3076.

Keep traditional Compare borders, connectors and hit detection aligned when SWT discovers new line metrics after scrolling. Use SWT's line coordinates while retaining Compare's height cache, preserving entries before the first mismatch and validating only populated entries. The geometry and scrolling regressions now run in the Compare CI suite.

A local macOS geometry-only benchmark with 100,000 lines, 500,000 color-only style ranges, 50-pixel spacing and 200 change positions measured a warmed median of 8.07 ms for the original production code and 5.26 ms for this change, including six cache validations. These indicative measurements invoke the production geometry methods; they are not timings for a complete editor repaint.

@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

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

    54 files  ± 0      54 suites  ±0   36m 23s ⏱️ - 1m 26s
 5 047 tests +25   5 025 ✅ +25   22 💤 ±0  0 ❌ ±0 
13 032 runs  +75  12 878 ✅ +75  154 💤 ±0  0 ❌ ±0 

Results for commit 3b1bf65. ± Comparison against base commit 30dafa8.

♻️ This comment has been updated with latest results.

@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?

@tobiasmelcher
tobiasmelcher force-pushed the d031119/fix-compare-scroll-geometry branch from 51a28ab to aba9009 Compare November 16, 2026 19:10
@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

Thank you very much, @vogella, for reproducing the issue and for such an excellent, thorough review! I've applied your feedback: the tests now run in the Compare suite with license headers, the duplicate check is removed, and cache invalidation preserves entries before the first mismatch. All 179 Compare tests pass.

Do you have a skill or prompt for agent-assisted code reviews that you could share? I should have caught the missing headers and suite registration in my own local agent review, and I'd really appreciate learning from your approach.

@vogella

vogella commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Thank you very much, @vogella, for reproducing the issue and for such an excellent, thorough review! I've applied your feedback: the tests now run in the Compare suite with license headers, the duplicate check is removed, and cache invalidation preserves entries before the first mismatch. All 179 Compare tests pass.

Technical feedback is arriving soon.

Do you have a skill or prompt for agent-assisted code reviews that you could share? I should have caught the missing headers and suite registration in my own local agent review, and I'd really appreciate learning from your approach.

Which model are you using? Opus 5.5 should have caught that. And for this review, I think I ask Opus "What do you think about PR 3077", nothing fancy. Simplicity rules with the new models.

@vogella

vogella commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Taking y from getLinePixel in getLineY looks right to me. My concerns are about the line height cache:

  1. Is the cache still needed? Since positions now come from getLinePixel, the cache only serves the box heights. Computing h as getLinePixel(to) - getLinePixel(from) would add about one lookup per change. Could you benchmark that variant? If it is close, dropping LineHeightCache would remove about 150 lines of state.
  2. Caching is now off in some setups. canCacheLineHeights requires line spacing > 0. With line spacing 0 plus code minings or vertical indents, getLinePixel walks line by line, and the old cache no longer covers that case.
  3. Validation cost per paint. validateLineHeightCache runs several times per repaint and on mouse events. Each run checks the indent of every populated line and usually calls getLinePixel over the whole cached prefix, so the cost grows with file size on every paint.
  4. Minor: getHeightBetweenLines checks cache.matches() a second time without anything changing in between. The out-of-range branch still adds getLineSpacing() once, which was already odd before this PR.
  5. Tests: they call getLineY, getHeightBetweenLines and paint through reflection, so any rename breaks them. Package visibility would be more robust.

Points 1 to 3 depend on whether the no-cache path is fast enough. If it is, using getLinePixel for both position and height would be the simplest fix.

Use SWT line coordinates to keep compare geometry aligned after scrolling while retaining the height cache. Validate populated entries before drawing, preserve entries before the first mismatching line and bypass the cache while widget metrics disagree. Add geometry and scrolling regressions to the Compare CI suite.

Fixes eclipse-platform#3076
@tobiasmelcher

tobiasmelcher commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I tested a two-way Java compare with two 31,005-line files and 5,168 differences. The performance tests, results and replay scripts are supplied separately as a ZIP attachment to this comment; the performance tests are not part of the PR.

compare3077-performance-tests.zip

Test machine: a desktop cloud VM with a fairly slow CPU: Intel Xeon Gold 6338N @ 2.20 GHz, 8 virtual CPUs, 32 GiB RAM, Windows 11 Enterprise, VMware, and SapMachine JDK 25. The absolute times reflect this cloud desktop; they should not be taken as timings for a fast local workstation. All versions used the same machine and current SWT/JFace/JDT runtime. I replayed the historical height calculations, rather than building complete old Eclipse releases.

  1. Is the cache still needed? Since positions now come from getLinePixel, the cache only serves the box heights. Computing h as getLinePixel(to) - getLinePixel(from) would add about one lookup per change. Could you benchmark that variant? If it is close, dropping LineHeightCache would remove about 150 lines of state.

I measured three things: opening the compare until both text panes had painted, scrolling to the middle until both panes had painted, and repainting both panes again. Times below are in milliseconds; lower is better. Completed results are medians of four runs after one warmup.

Version or experiment Open Middle scroll Repaint
Before the cache (#1492) 4,512 Still blocked after 397,731 Not reached
Original cache from #1492 2,445 3,075 276
Cached code just before #3077 2,482 3,284 544
#3077 as reviewed 2,510 1,182 404
#3077 with validation disabled 2,486 1,161 399
#3077 using live widget coordinates for heights 2,476 1,801 1,746
#3077 with the zero-spacing cache fix — chosen approach 2,449 1,554 588

These runs use the 50% line-spacing preference, which produced 5 pixels of spacing here. The old code was stopped by a watchdog while scrolling; its result is an incomplete observation, not a completed timing.

The first three rows show the old code without caching, the first cache implementation, and the cached code immediately before this PR. The next row is this PR as reviewed. I then tried two alternatives: skipping cache validation, and calculating heights directly from SWT's current line coordinates. The final row is this PR with caching also allowed at zero line spacing.

I propose keeping the cache and its validation, and fixing the zero-spacing restriction. Opening alone misses the old performance problem: scrolling is where the pre-cache code became stuck. Using live coordinates also made repainting over four times slower than this PR as reviewed, and about three times slower than the final fix. PR #1492 did not include an automated reproducer; its linked issue #2143 describes a manual large-file reproduction.

Compared with the cached code just before #3077, the final fix made the measured middle scroll about 53% faster (3,284 to 1,554 ms). Opening was about the same (2,482 to 2,449 ms), while repainting was about 8% slower (544 to 588 ms). The fix improves middle-scroll performance and addresses correctness, but it does not improve every timing. This comparison uses the recorded pre-#3077 revision, not a fresh measurement of today's master.

I consider the measured 8% repaint slowdown an acceptable tradeoff for the correctness fix, especially with the substantial improvement in middle scrolling. I would proceed with the cache, validation and zero-spacing fix in this PR.

  1. Caching is now off in some setups. canCacheLineHeights requires line spacing > 0. With line spacing 0 plus code minings or vertical indents, getLinePixel walks line by line, and the old cache no longer covers that case.

You were right that caching was disabled in some setups. I reproduced zero line spacing with extra vertical space above some lines, as used for code minings. The new correctness regression fails on the reviewed PR and passes with the fix. In that scenario:

Zero spacing with extra space above lines Open Middle scroll Repaint
#3077 as reviewed 2,091 808 784
#3077 with the fix 2,087 1,273 465

Repainting improved, but the first middle scroll was slower. The positive-spacing repaint was also slower in the final run (588 vs 404 ms), with variable samples. I have included both fixed runs in the attachment; the cause of that increase is not established.

  1. Validation cost per paint. validateLineHeightCache runs several times per repaint and on mouse events. Each run checks the indent of every populated line and usually calls getLinePixel over the whole cached prefix, so the cost grows with file size on every paint.

Validation did not show a significant cost here: disabling it changed repainting from 404 to 399 ms. A separate measurement of validation alone took 0.11 ms for the cache populated by this workload and 0.79 ms with all 31,005 lines populated. These results support keeping the correctness checks for this workload.

  1. Minor: getHeightBetweenLines checks cache.matches() a second time without anything changing in between. The out-of-range branch still adds getLineSpacing() once, which was already odd before this PR.

I am leaving the minor cleanup in point 4 unchanged. If you consider it important, please handle it in a separate PR so I can focus on the correctness and performance work here.

  1. Tests: they call getLineY, getHeightBetweenLines and paint through reflection, so any rename breaks them. Package visibility would be more robust.

I implemented point 5: the geometry/paint methods are package-visible, and the tests call them through the existing internal test adapter instead of reflection. A fresh Maven verify on the final PR sources passed all 25 geometry and scrolling tests, with zero failures, errors or skips.

@tobiasmelcher
tobiasmelcher force-pushed the d031119/fix-compare-scroll-geometry branch from aba9009 to 3b1bf65 Compare November 17, 2026 11:33
@vogella

vogella commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Thanks for the performance result, they look good to me, 53% is nice. :-)

You also ask for tips with using LLMs, one thing which would make looking at your responses more efficient for me, is if you would instruct your AI Engine to write more concisely. For example, add a memory which says: "Answer concisely in pull requests and use concise descriptions for new PRs."

@vogella vogella left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

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