Skip to content

Conversation

kwvanderlinde
Copy link
Collaborator

@kwvanderlinde kwvanderlinde commented Sep 24, 2025

Identify the Bug or Feature request

Resolves #5795

Description of the Change

This tackles the key points mentioned in #5795:

  1. Memory usage is much more constrained when using the performance window. This is due to using JTextArea#append(String) instead of JTextComponent#setText(String), which lets us avoid string concatenations and lets the text area avoiding reallocating lots of undo and cursor tracking information.
  2. Times can be reported and configured in any unit. The ZoneRenderer in particular uses microseconds for reporting, and sets its threshold much lower at 1 microsecond.
  3. The font in the performance window is now monospaced so that adjacent lines are more aligned.

There are also a few other improvements done along the way:

  • GdxRenderer has updated CodeTimer usage, i.e., works with CodeTimer.using(...) rather than managing its own CodeTimer instance.
  • All renderers will use their name in the timer name so it is clear where the times come from. This includes the timers in RenderHelper, which now supports a configurable prefix for its timers.
  • When CodeTimer encounters unbalanced start() and end() calls, it now logs them as a warning rather than throwing an exception. A user should not be bothered by a dialog for such non-critical logic errors.
  • CodeTimer tries to stay out of the way as much as possible. Instead of doing map lookups and string formatting in start(), stop(), and increment() calls, these instead append some information to a running list. When done with the CodeTimer, the results are compiled and reported out of band, so as not to hold up the rendering.

Possible Drawbacks

CodeTimer will have different performance characteristics, so we'll have to keep on eye on things to make sure it isn't worse in some situations.

Documentation Notes

N/A

Release Notes

  • Improved memory usage and when Collect Performance Data is enabled.

This change is Reviewable

@kwvanderlinde kwvanderlinde self-assigned this Sep 24, 2025
@github-actions github-actions bot added code-maintenance Adding/editing javadocs, unit tests, formatting. performance A performance or quality of life improvement labels Sep 24, 2025
With this, the `CodeTimer` constructor no longer needs to be public.
The font is now monospace so that the various lines are aligned with one another. The text area is also now uneditable
so it doesn't have to worry about things like tracking undo state.

The major change here is that text is added to the performance window via `JTextArea#append(String)` instead of
`JTextComponent#setText(String)`. The former does not require us to do string concatenation (which is expensive when the
contents are large), and means the text area's document does not have to reallocate a lot of its internal state.
This makes it easier to see which part of the rendering process is responsible for which slowdowns. To make this work,
`RenderHelper` can have custom prefixes set by the renderers so that we can distinguish `RenderHelper` operations coming
from, say, the `FogRenderer` vs the `LightsRenderer`.
@kwvanderlinde kwvanderlinde force-pushed the performance/5795-timer-improvements branch from c3dacee to 42cbb6d Compare September 24, 2025 20:47
@kwvanderlinde kwvanderlinde moved this from Todo to Awaiting-Review in MapTool 1.19 Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-maintenance Adding/editing javadocs, unit tests, formatting. performance A performance or quality of life improvement
Projects
Status: Awaiting-Review
Development

Successfully merging this pull request may close these issues.

[Maintenance]: Timing improvements
1 participant