Repository navigation
Keep compare borders aligned when line heights change - #3077
tobiasmelcher wants to merge 1 commit into
Conversation
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
2811a31 to
51a28ab
Compare
|
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? |
|
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:
|
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.