-
Notifications
You must be signed in to change notification settings - Fork 202
TaskTableModel optimizations
#7756
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
base: main
Are you sure you want to change the base?
TaskTableModel optimizations
#7756
Conversation
| if (tech == null) { | ||
| tech = panel.getTempTech(); | ||
| } | ||
| if (null == tech) { |
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.
Format these the same
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #7756 +/- ##
============================================
- Coverage 12.13% 12.12% -0.01%
+ Complexity 7313 7307 -6
============================================
Files 1210 1210
Lines 152774 152803 +29
Branches 23123 23127 +4
============================================
- Hits 18540 18534 -6
- Misses 132318 132347 +29
- Partials 1916 1922 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Pull Request Overview
Optimize TaskTableModel rendering and tech selection to reduce repeated computation and UI churn
- Only adjust table row height when necessary to avoid repeated resets during rendering
- Cache a "temp tech" in panels when no tech is selected to avoid repeated tech list scans
- Extend ITechWorkPanel with temp tech getters/setters and implement in RepairTab and WarehouseTab
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| MekHQ/src/mekhq/gui/model/TaskTableModel.java | Optimize row height setting and introduce use of cached temp tech when no tech is selected |
| MekHQ/src/mekhq/gui/WarehouseTab.java | Add tempTech storage and implement ITechWorkPanel’s new getters/setters |
| MekHQ/src/mekhq/gui/RepairTab.java | Add tempTech storage, implement ITechWorkPanel’s new getters/setters, and initialize new field |
| MekHQ/src/mekhq/gui/ITechWorkPanel.java | Extend interface with temp tech accessors |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| table.setRowHeight(UIUtil.scaleForGUI(100)); | ||
| int newRowHeight = UIUtil.scaleForGUI(100); | ||
| if (table.getRowHeight(row) != newRowHeight) { | ||
| table.setRowHeight(newRowHeight); |
Copilot
AI
Oct 19, 2025
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 compares a per-row height (getRowHeight(row)) but updates the table-wide default height (setRowHeight(rowHeight)), which is inconsistent and can lead to unnecessary updates or overriding per-row custom heights. Compare against the default with table.getRowHeight() or set the specific row height using table.setRowHeight(row, newRowHeight). Example fix: if (table.getRowHeight() != newRowHeight) { table.setRowHeight(newRowHeight); }
| table.setRowHeight(newRowHeight); | |
| table.setRowHeight(row, newRowHeight); |
| Person tech = panel.getSelectedTech(); | ||
|
|
||
| if (tech == null) { | ||
| tech = panel.getTempTech(); |
Copilot
AI
Oct 19, 2025
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.
A cached temp tech is used without verifying it can service the current entity, which can produce incorrect behavior when switching between parts or units with different tech requirements. Guard the reuse with a capability check and fall back to the search if incompatible, e.g.: if (tech == null) { Person cached = panel.getTempTech(); if (cached != null && cached.canTech(part.getUnit().getEntity())) { tech = cached; } }
| tech = panel.getTempTech(); | |
| Person cachedTech = panel.getTempTech(); | |
| if (cachedTech != null && part.getUnit() != null && cachedTech.canTech(part.getUnit().getEntity())) { | |
| tech = cachedTech; | |
| } |
| private int selectedLocation = -1; | ||
| private Unit selectedUnit = null; | ||
| private Person selectedTech = getSelectedTech(); | ||
| private Person tempTech = getTempTech(); |
Copilot
AI
Oct 19, 2025
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.
[nitpick] Initializing a field by calling its own getter during field initialization is confusing and unnecessary; it will just assign the default null via an instance method before construction completes. Prefer a plain declaration: private Person tempTech; and let it be managed via the getter/setter.
| private Person tempTech = getTempTech(); | |
| private Person tempTech; |
| IPartWork getSelectedTask(); | ||
|
|
||
| Person getSelectedTech(); | ||
|
|
||
| Person getTempTech(); | ||
|
|
||
| void setTempTech(Person tempTech); | ||
| } |
Copilot
AI
Oct 19, 2025
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.
New API methods lack Javadoc/comments describing intended semantics (e.g., when tempTech should be set/cleared, thread-safety expectations, and that the cached tech must be compatible with the current part/unit). Please add brief Javadoc to guide implementers.
| IPartWork getSelectedTask(); | |
| Person getSelectedTech(); | |
| Person getTempTech(); | |
| void setTempTech(Person tempTech); | |
| } | |
| /** | |
| * Returns the currently selected task for tech work. | |
| * Implementers should ensure the returned task is compatible with the current part/unit. | |
| * | |
| * @return the selected IPartWork task, or null if none is selected | |
| */ | |
| IPartWork getSelectedTask(); | |
| /** | |
| * Returns the currently selected technician for the task. | |
| * The returned Person should be valid for the current part/unit. | |
| * | |
| * @return the selected Person as technician, or null if none is selected | |
| */ | |
| Person getSelectedTech(); | |
| /** | |
| * Returns the temporary technician assigned to the current task. | |
| * This is typically used for previewing or staging a tech assignment before confirmation. | |
| * Implementers should clear tempTech when the assignment is finalized or cancelled. | |
| * Thread-safety: If this panel is accessed from multiple threads, ensure proper synchronization. | |
| * | |
| * @return the temporary Person assigned as technician, or null if none is set | |
| */ | |
| Person getTempTech(); | |
| /** | |
| * Sets the temporary technician for the current task. | |
| * Use this to stage a tech assignment before confirmation. | |
| * The provided Person must be compatible with the current part/unit. | |
| * Implementers should clear tempTech when the assignment is finalized or cancelled. | |
| * Thread-safety: If this panel is accessed from multiple threads, ensure proper synchronization. | |
| * | |
| * @param tempTech the Person to set as temporary technician, or null to clear | |
| */ | |
| void setTempTech(Person tempTech); |
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.
Unless the setter or getter does anything special it doesn't need to be javadoc. Even I don't javadoc setters and getters and I javadoc everything.
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.
Don't waste your time on this PR, doesn't quite work right anyway ;) I'll un-draft it / ask for input when it's less bad. But something's gotta be done, it looks like it just constantly recalculates values when you're sitting on the tab. Something I'll keep messing with...
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.
That actually matches what I was finding last time I was in this corner of the code. It's not just an issue restricted to here.
The campaign summary section, on the command center tab (the bit where it shows your unit rating, etc). Used to be constantly refreshing itself. I think I changed that to only refresh on new day. But, obviously, that won't work here.
Flame graph before changes:

Flame graph after changes:

When changes happen to the table, and the user hasn't selected a Tech, it will now store a "temp tech" for that panel so it doesn't need to repeatedly get the entire list of techs and filter it down for a temp tech.
Also stops row height from repeatedly adjusting itself.