-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Remove listeners in UndoAction and RedoAction for memory efficiency #11839
Conversation
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.
Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.
You can check review dog's comments at the tab "Files changed" of your pull request.
Checkstyle says
|
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.
Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.
You can check review dog's comments at the tab "Files changed" of your pull request.
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.
Minor formatting changes requested. Otherwise LGTM.
Thank you for your contribution!
P.S. Do mark the mandatory checks that you have completed in the PR description when you file one (the ones that apply).
* @implNote See also {@link UndoAction} | ||
* @implNote | ||
* See | ||
* also | ||
* {@link | ||
* UndoAction} |
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.
Revert this
} catch (CannotRedoException ex) { | ||
} catch ( | ||
CannotRedoException ex) { |
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.
Please also fix the catch indent (not your fault, IntelliJ does this by default when we format the document).
activeLibraryTab.ifPresent(libraryTab -> | ||
this.executable.bind(libraryTab.getUndoManager().getRedoableProperty())); | ||
}); | ||
|
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.
This empty line is not necessary, is it?
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.
actually this empty line is for exists to separate lines 30 and 32 from each other. But I can remove.
@subhramit We should test this. This PR implements both suggestions of you (#11809 (comment)). I think, one needs to open 5 to 10 libraries, switch tabs back and forth, modifying the library and see if undo/redo is enabled properly. @melisolmez For consistency reasons, this patch also nees to be ported to the UndoAction. Undo is the twin of Redo. --> https://github.com/JabRef/jabref/blob/8412e651b671a427c828924ce5698eb4c32f269d/src/main/java/org/jabref/gui/undo/UndoAction.java |
Okey. Should I send it to the same branch? |
Actually, suggestion 1 was to conditionally but explicitly use What is probably confusing - use of |
this.executable.bind(libraryTab.getUndoManager().getRedoableProperty())); | ||
}); | ||
|
||
oldValue.ifPresent(libraryTab -> this.executable.unbind()); |
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.
Thinking a bit more, I am a bit concerned about the order of operations here.
Case 1:
State A->B - change detected, bind to B, unbind if oldValue is not null. After this,
State B->A - change detected, bind to A (not needed), unbind if B (oldvalue) is not null, which is true, so unbind (this is fine).
Case 2:
State A->B - change detected, bind to B, unbind if oldValue is not null. After this,
State B->C - change detected, bind to C, unbind if B is not null (which is true) - thus executable is not bound.
@Siedlerchr would it be better if we don't unbind at all here? Or is this alright as LibraryTab can never have a third state "C"?
Undo/Redo are part of the same component, IMO this PR should handle both of them. |
@HoussemNasri hello, Could you review the pr? |
More details: Compare it with the main branch. You will find that in your branch, on adding the author name, it is not reflected in the Author/Editor column of the entry (until some sequence of events - changing tabs, pressing enter, etc.) My hypothesis: the early unbinding (described in #11839 (comment)) is causing nothing to be bound, and thus no listeners are attached at all, and thus no changes are reflected. Fix: The unbinding should not happen where it is currently. Remove it, profile the memory using VirtualVM to test the changes. We profiled it on the main branch - on adding tabs, the used heap size was shooting up, whereas in your branch the garbage collector did kick in, reducing the heap size on closing tabs. If the sequence becomes too confusing, you can also use plain old Apologies that the testing part may make this a bit more involved than a good first issue. |
Thank you for your feedbak. I will look at it in more detail |
Hi @subhramit, I tested what you said but I couldn't find where it was wrong. When I add author name it is reflected in the Author/Editor column. and the undo and redo buttons active. I don't understand exactly what the problem is, can you explain it in more detail? |
Will try to send you a video. |
I am unable to reproduce what @Siedlerchr did, the undo/redo buttons are staying disabled for me:
|
In the above case, I closed some previously opened libraries. Both the Undo/Redo buttons are active even though no changes have been made/ no entries have been added. |
The two issues mentioned above persist even on removing the line that unbinds the executable (my hypothesis fails). Hence, we need to redo this PR. |
@melisolmez I think the other maintainers are presently a bit busy, and we appreciate your patience in sticking to the task.
I think testing can be less confusing if #11837 is solved first, but that is optional - you can also pick it up if interested, or continue with this one. |
Hello @subhramit, I tested your sayng but I couldn't find the wrong things where.
Hello @subhramit thank you for help. I understand what is the problem and I will try fix it.
|
Good questions. jabref/src/main/java/org/jabref/gui/undo/CountingUndoManager.java Lines 27 to 31 in 4b8d668
Thus, I would start at |
More thoughts: if (databases == null || databases.isEmpty()) Then the properties should be set to disabled. |
@Siedlerchr can we use Injector to get |
one liner |
Hi @subhramit, I am trying the fix problem. I noticed a few things and I wanted to share with you maybe they will help. as first: I examined CountingUndoManager.java class with debug. While the project is getting off the ground, it does not fall into this class. It only entered this class when the library is added. When I added situation here and try to disable the buttons, they remain disabled throughout the application. so this was not the solution second: As far as I understand, buttons were created using the RedoAction and UndoAction classes in the MainMenu.java class.And this one I added situation in RedoAction and UndoAction constructor and try to disable the buttons. but this solution didn't work either. I don't know if I'm doing it right I'm just trying something |
Hello @melisolmez, Thank you for your hard work in addressing this issue. The Undo/Redo feature is indeed quite challenging, especially given its current state, which requires significant refactoring. We'll take over from here and continue refining the pull request to bring it to a mergeable state. In the meantime, feel free to explore other good first issues and comment on any that interest you and someone will assign it to you. |
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.
Thank you again for your work! We truly appreciate your efforts and look forward to more contributions.
Fix #11809
Fix #11837
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)