-
Notifications
You must be signed in to change notification settings - Fork 109
Fix UI flickering in code mining by adding wait/notify reconciliation coordination #2698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix UI flickering in code mining by adding wait/notify reconciliation coordination #2698
Conversation
jjohnstn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as stated and logic seems reasonable. I noticed in eclipse-platform/eclipse.platform.ui#2786 (comment) that you mention that you aren't sure about waiting for reconcile to finish and @laeubi states that waiting is never a good idea with a CompletableFuture, however, this patch does wait in the CompletableFuture. I didn't see you respond to @laeubi's comment. Can you comment here?
|
That seems like a good change |
|
@jjohnstn yes that's right. But on the other hand of course in a legacy code base one might need to do it incrementally. To explain the problem here what will happen is that there is a thread allocated from the common pool just for waiting. This decreases the possible concurrency level and the jvm will allocate possibly more threads... not so good but I would assume that reconciliation is hopefully fast, 30 seconds sounds way to much. Also keep in mind that spurious wakeups are possible to 30sec is just the maximum it will wait... you usually will need a while loop in this case. Also currently it seems to use ONE lock for ALL editors... meaning one (unrelated) editor can block others (e.g. two windows showing different source files). I just want to outline how it would suppose to work in the best case:
That way one does not need an additional waiting thread or additional resource allocation and no need for basic synchronize primitives. |
laeubi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tobiasmelcher thanks for your proposal I think it goes in the right direction already, I have added some comments below.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaCodeMiningReconciler.java
Outdated
Show resolved
Hide resolved
| public void aboutToBeReconciled() { | ||
| // interrupt code minings if modification occurs | ||
| reconciledViewers.remove(fSourceViewer); | ||
| toBeReconciledViewers.computeIfAbsent(fSourceViewer, unused->{return new CompletableFuture<CompilationUnit>();}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would more would use compute here and then check if there is already one (and cancel it) and creating always a fresh one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toBeReconciledViewers.compute(fSourceViewer, (viewer, existingFuture) -> {
if (existingFuture != null) {
existingFuture.cancel(false);
}
return new CompletableFuture<CompilationUnit>();
});
I tried with this code; but then it started again flickering. Reason: the canceled future now no longer returns the code minings and therefore the framework is removing the previous code minings provided by the Java implementation.
Maybe, I didn't get what you want to achieve. But I think that calling "cancel" will introduce the flickering again. Please convince me from the opposite if you think that calling "cancel" is a good idea.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaCodeMiningReconciler.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaCodeMiningReconciler.java
Outdated
Show resolved
Hide resolved
...t.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/codemining/JavaElementCodeMiningProvider.java
Outdated
Show resolved
Hide resolved
...t.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/codemining/JavaElementCodeMiningProvider.java
Outdated
Show resolved
Hide resolved
...t.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/codemining/JavaElementCodeMiningProvider.java
Show resolved
Hide resolved
laeubi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See some comments below
...t.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/codemining/JavaElementCodeMiningProvider.java
Outdated
Show resolved
Hide resolved
...t.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/codemining/JavaElementCodeMiningProvider.java
Show resolved
Hide resolved
...org/eclipse/jdt/internal/ui/javaeditor/codemining/JavaMethodParameterCodeMiningProvider.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaCodeMiningReconciler.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaCodeMiningReconciler.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaCodeMiningReconciler.java
Outdated
Show resolved
Hide resolved
|
Thank you so much for taking the time to review my work and share your feedback; I really appreciate your effort and support. in JavaElementCodeMiningProvider, and explaining why monitor.setCanceled(true) needs to be called so that the CodeMiningFramework does not delete previous code minings from the Java provider and flickering occurs. |
laeubi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the improvements I think its overall going in a good direction, I added two more comments here.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaCodeMiningReconciler.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaCodeMiningReconciler.java
Outdated
Show resolved
Hide resolved
73fe5ab to
52a105a
Compare
coordination Problem: Previous implementation returned emptyList() immediately when reconciliation wasn't complete, causing code minings to disappear/reappear during AST reconciliation → UI flickering Solution: - Add shared RECONCILE_LOCK and reconciledViewers Set for coordination - Code mining provider now *waits* (up to 30s) for reconciliation to complete - Reconciler signals completion with notifyAll() in reconciled() - Remove viewer from reconciled set in aboutToBeReconciled() during edits
52a105a to
b7da8a6
Compare
laeubi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks almost good to me, just some more comments of some details from my side.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaCodeMiningReconciler.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaCodeMiningReconciler.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaCodeMiningReconciler.java
Outdated
Show resolved
Hide resolved
...org/eclipse/jdt/internal/ui/javaeditor/codemining/JavaMethodParameterCodeMiningProvider.java
Show resolved
Hide resolved
|
@tobiasmelcher : could you please follow up on review comments, mark all resolved and fix / discuss not resolved, so that we could target this for merge soon? |
I have already done the requested changes with [8246b94] |
|
@laeubi: Can you pls. re-review? |
laeubi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks fine to me
jjohnstn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Thanks @tobias-melcher looking forward in using code minings more now. |
@vogella please let me know if you find bugs or strange effects with rendering of the code minings |
Thanks @tobias-melcher. AFAICS the flickering during save has been fixed. (Scenario: delete some code and methods outside the scope of the change would flicker as they remove and redrawn their code mining). From a first test, it looks like code minings are not always drawn without resetting the preferences, attached a small exampe, let me know if I should open a new issue for this. |
Thanks a lot for reporting this issue @vogella . I was able to reproduce the scenario and provide a fix with eclipse-platform/eclipse.platform.ui#3689 . Could you please help with the review? |

Problem: Previous implementation returned emptyList() immediately when reconciliation wasn't complete, causing code minings to disappear/reappear during AST reconciliation → UI flickering
Solution:
This pull request will solve following reported issue eclipse-platform/eclipse.platform.ui#2786 (comment)