Performance degradation with lombok - #4713
Conversation
|
Could you please provide a regression test? |
Can I start tests with the |
Should be possible to start JVM from the test with extra arguments, the tests itself don't have individual configurations AFAIK. |
|
@iloveeclipse |
@iloveeclipse I have added ASTConverter18Test.testIssue4712() |
|
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. |
|
I've just rebased on master |
There was a problem hiding this comment.
Pull request overview
Addresses Eclipse JDT issue #4712 (“Performance degradation with lombok”) by avoiding expensive comment-mapping/scanning work when the AST contains synthetic/generated nodes with invalid/empty source ranges, and by tightening comment-mapper initialization.
Changes:
- Skip visiting/comment-mapping for generated AST nodes (and generated siblings) in
DefaultCommentMapper. - Avoid initializing
DefaultCommentMapperwhen the compilation unit has no comments. - Add a regression test covering the reported scenario and harden the scanner against negative positions.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultCommentMapper.java |
Skips generated nodes/siblings during comment mapping to prevent pathological scanning behavior. |
org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnit.java |
Only initializes the comment mapper when there are actual comments to map. |
org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java |
Adds a regression test for issue #4712 (currently includes a time-based assertion). |
org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Scanner.java |
Guards scanning against negative currentPosition after an IndexOutOfBoundsException. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // The convertCompilationUnit method would need to take less than one second to complete. | ||
| assertTrue((System.currentTimeMillis() - start) < 1000); |
There was a problem hiding this comment.
This test asserts a hard 1s wall-clock limit for AST.convertCompilationUnit(), which is likely to be flaky on slower/loaded CI agents and can cause unrelated failures. Consider replacing the time-based assertion with a deterministic functional assertion (e.g., verify comment mapping behavior for generated nodes) or moving this into the existing performance test infrastructure / using a much more resilient threshold with clear skip/assumption rules for slow environments.
There was a problem hiding this comment.
AST.convertCompilationUnit() takes less than 20 ms.
There was a problem hiding this comment.
Not on a virtual build server that randomly pauses
stephan-herrmann
left a comment
There was a problem hiding this comment.
@snjeza strictly speaking this looks like a bug in lombok not in JDT (see my comment on the test). To avoid infinite bug ping pong I could be persuaded to accept the fix (as extra resilience) if you add comments to each changed code location explaining that we are handling illegal input specifically from lombok.
This is relevant for two reasons:
- we don't want to give the impression that 0 is a normal / expected value in any of these position fields, we would otherwise start inserting millions of 0-comparisons in all of our code base.
- this also raises the question: perhaps that lombok bug could surface in many other locations in JDT as well?
- people working on these code sections in the future need to know that the reason for the added checks lies outside JDT, otherwise folks might light-heartedly removed them.
| printlnCall.arguments = null; | ||
| printlnCall.sourceStart = typeDecl.sourceStart; | ||
| printlnCall.sourceEnd = typeDecl.sourceEnd; | ||
| printlnCall.nameSourcePosition = 0L; |
There was a problem hiding this comment.
Strictly speaking, this assignment is illegal: org.eclipse.jdt.internal.compiler.ast.MessageSend clearly is an internal class, not intended for access by clients. For that reason we can simply say that 0L is an illegal value for field nameSourcePosition, and none of our code is obliged to handle it.
| ASTNode sibling = parent == this.topSiblingParent ? (ASTNode) this.siblings[this.siblingPtr] : null; | ||
| if (sibling != null) { | ||
| // skip generated node - https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4712 | ||
| if (sibling != null && sibling.getLength() > 0) { |
There was a problem hiding this comment.
addition is not needed to pass the new test
| ASTNode sibling = this.topSiblingParent == node ? (ASTNode) this.siblings[this.siblingPtr] : null; | ||
| if (sibling != null) { | ||
| // skip generated node - https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4712 | ||
| if (sibling != null && sibling.getLength() > 0) { |
There was a problem hiding this comment.
not covered either
|
@stephan-herrmann I have updated the PR. |
Thanks. Could you please also comment on the changes that are not covered by your test? I think just the change in Scanner makes it pass, no? Did you observe problems in the other locations in real life? Edit: Just now I discovered your second force-push which brings new tests. I'll look at them shortly. Edit2: NO, that second force push doesn't look like any new tests from you. Please help me understand what you are doing when pushing to the PR, thanks. |
I have added a comment to each of the four changed files:
The PR includes only one test -
I have done the following: |
Thanks. Also there might have been a misunderstanding regarding this:
By "comment on" I didn't mean to ask for additional code comments right now. First I wanted to understand, why you made some code changes that are not needed by your test case. Can you please explain? |
I have only added the following comment to all the changed files:
Compared to the original PR, I haven’t changed the code.
I have checked the issue described on redhat-developer/vscode-java#4052 using https://github.com/ipkiss42/vscode-java-4052 |
Fixes #4712