Fix TargetPlatformPresentationReconciler: stop scanning past damage end#2284
Fix TargetPlatformPresentationReconciler: stop scanning past damage end#2284vogella wants to merge 2 commits intoeclipse-pde:masterfrom
Conversation
|
This pull request changes some projects for the first time in this development cycle. An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch. Git patchFurther information are available in Common Build Issues - Missing version increments. |
ad4c2fd to
e08d95d
Compare
Test Results 150 files + 3 150 suites +3 36m 50s ⏱️ + 1m 29s For more details on these failures, see this check. Results for commit 58c2c98. ± Comparison against base commit 50600c6. ♻️ This comment has been updated with latest results. |
30a7061 to
c91f39e
Compare
c91f39e to
a2b3bb3
Compare
There was a problem hiding this comment.
Pull request overview
Improves the Generic Target Platform Editor’s syntax highlighting reconciler performance by avoiding unnecessary full-document partition scanning while preserving correctness for multi-line XML comment rules.
Changes:
- Limit
TargetPlatformPresentationReconcilerpartition scan length to the end of the damage region (still starting at offset 0). - Export
reconciler.presentationas a “friend” package to enable test subclassing. - Add a new JUnit test class and wire it into the existing test suite; bump test bundle versions accordingly.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
.../TargetPlatformPresentationReconciler.java |
Stops partition scanning at damage end instead of document end to reduce UI-thread work. |
.../org.eclipse.pde.genericeditor.extension/META-INF/MANIFEST.MF |
Marks reconciler.presentation as x-friends for the test bundle. |
.../TargetPlatformPresentationReconcilerTest.java |
Adds new tests for reconciler behavior across damage/comment scenarios. |
.../AllTargetEditorTests.java |
Includes the new reconciler test class in the suite. |
.../org.eclipse.pde.genericeditor.extension.tests/pom.xml |
Bumps test bundle Maven version. |
.../org.eclipse.pde.genericeditor.extension.tests/META-INF/MANIFEST.MF |
Bumps OSGi bundle version. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| int scanEnd = damage.getOffset() + damage.getLength(); | ||
| ITypedRegion[] regions = TextUtilities.computePartitioning(document, getDocumentPartitioning(), 0, | ||
| document.getLength(), false); | ||
| scanEnd, false); |
There was a problem hiding this comment.
scanEnd is derived from damage.getOffset() + damage.getLength() and is passed to TextUtilities.computePartitioning(...) as the length parameter. If the provided damage region ever extends past the current document.getLength() (e.g., due to a stale damage region during rapid edits), computePartitioning will throw BadLocationException and this method returns null, potentially breaking syntax highlighting. Consider clamping the computed scan length to document.getLength() (and generally ensuring it is within valid bounds) before calling computePartitioning.
| @Test | ||
| public void testCreatePresentationReturnsNonNullForSimpleDocument() { | ||
| TestableReconciler reconciler = new TestableReconciler(); | ||
| String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" //$NON-NLS-1$ | ||
| + "<target name=\"test\">\n" //$NON-NLS-1$ | ||
| + " <locations/>\n" //$NON-NLS-1$ | ||
| + "</target>\n"; //$NON-NLS-1$ | ||
| IDocument document = new Document(content); | ||
| IRegion damage = new Region(0, content.length()); | ||
|
|
||
| TextPresentation presentation = reconciler.createPresentation(document, damage); | ||
|
|
||
| assertNotNull("Expected a non-null TextPresentation for a simple document", presentation); //$NON-NLS-1$ | ||
| } |
There was a problem hiding this comment.
These tests only assert that createPresentation(...) returns a non-null TextPresentation, which would still pass even if the reconciler kept scanning to the end of the document (the original regression) or produced incorrect styling. To make this a meaningful regression test for the performance fix, consider installing a custom IDocumentPartitioner (or similar hook) on the IDocument that records the offset/length requested by TextUtilities.computePartitioning, then assert that the computed length matches damage.getOffset() + damage.getLength() rather than document.getLength().
a2b3bb3 to
31f0806
Compare
The reconciler always scanned the full document (offset 0 to document.getLength()) on every keystroke to ensure multi-line XML comment rules are honoured. While scanning from offset 0 is required for correctness, scanning *past* the damage end is wasted work because the returned TextPresentation is bounded by the damage region and silently discards any style ranges beyond it. Change the upper bound of TextUtilities.computePartitioning() from document.getLength() to damage.getOffset() + damage.getLength(). This avoids scanning content whose results would be thrown away, while preserving the full-context scan from offset 0 that multi-line rules require. Add TargetPlatformPresentationReconcilerTest to verify correctness for the common cases: simple documents, partial damage regions, multi-line comments before the damage, and damage inside a multi-line comment. Fixes: eclipse-pde#2283 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
31f0806 to
58c2c98
Compare
Summary
Fixes #2283 (also related to eclipse-platform/eclipse.platform.ui#2276).
TargetPlatformPresentationReconciler.createPresentation()overrides the defaultPresentationReconcilerbehaviour to always scan from offset 0. This isnecessary to correctly handle multi-line XML comment rules (
<!-- ... -->):without the full context from the start of the document, a comment that opened
before the damaged region would not be recognised.
However, the scan was running all the way to
document.getLength()even thoughthe
TextPresentationreturned is constructed with the damage region as itsextent — meaning any style ranges added for content after the damage end are
silently discarded. This results in O(document length) work on the UI thread
for every keystroke, causing noticeable freezes in large
.targetfiles.Changes
TargetPlatformPresentationReconciler— change the upper bound ofTextUtilities.computePartitioning()fromdocument.getLength()todamage.getOffset() + damage.getLength(). Scanning still starts at offset 0(multi-line rule correctness is preserved); it just stops where it would have
discarded results anyway.
MANIFEST.MF(genericeditor.extension) — declareorg.eclipse.pde.genericeditor.extension.testsas a friend of thereconciler.presentationpackage so the new tests can subclass the reconciler.TargetPlatformPresentationReconcilerTest— new test class covering:Known limitation
For edits very close to the end of a large file the gain is small (the damage
end ≈ the document end). A more thorough fix — e.g. caching scanner state
between edits, using a real
IDocumentPartitionerfor comments, or movingreconciliation off the UI thread — is left for a follow-up.
Test plan
mvn clean compileon the two affected bundles)TargetPlatformPresentationReconcilerTestpasses in a running Eclipse test environmentAllTargetEditorTestscontinue to pass🤖 Generated with Claude Code