RPTools / maptool

Virtual Tabletop for playing roleplaying games with remote players or face to face.
http://rptools.net
GNU Affero General Public License v3.0
797 stars 260 forks source link

Macro buttons with images appear to trigger memory leak in macro editor, other macro management task performance issues #1026

Open RicoTheBold opened 4 years ago

RicoTheBold commented 4 years ago

Describe the bug Under specific circumstances, opening the macro editor and saving a changed macro will consume a disproportionately high level of memory that is never released. These circumstances appear to involve many macros with asset IDs referenced in their names. It also appears that performance of several macro-manipulation actions (saving, clearing groups) is also impaired.

To Reproduce Steps to reproduce the behavior:

(other performance issues are noted below)

To not reproduce (control/negative test) On step 3, choose the Campaign panel. Follow steps 4-7.

Other notes - references to panels are specific to this test campaign file

Expected behavior Opening and saving a one-line macro should not 100-200MB of memory when the entire campaign file is < 3 MB. Slowdown should not occur in macro-saving options or group-clearing options when macros have images in the name.

Screenshots

Test of issue (GM panel macros) Cleared caches to start: cleared caches - no files

Memory after loading campaign: Starting memory - campaign load - GM panel test

Memory after editing 6 macros on the GM panel: after 6 GM panel macros changed

Memory after editing 17 macros on the GM panel: after 17 GM panel macros changed

Memory after editing 27 macros on the GM panel: after 27 GM panel macros changed

Memory after editing 30 macros on the GM panel (I stopped here because my heap space was set to 6 GB, and it absolutely will give you heap errors if you continue): after 30 GM panel macros changed

Memory after double-clicking the memory bar (didn't seem to reclaim any this time - possibly too close to the heap space maximum...): (Oops, apparently I overwrote this screenshot. Basically it looked unchanged, but usually I can reclaim around .15 to .3 GB)

Control/Negative test (Campaign panel macros) Immediately after restarting and loading the campaign to test using the macros on the campaign panel Starting memory - campaign load - Campaign panel test

Memory after editing 15 campaign panel macros:

(Note that this has less memory used than immediately after load. This is accurate to what happened during the test. Memory usage seems to jump up some at times, particularly while loading/saving macros, but occasionally get cleared out in a way that doesn't seem to happen in the other test. I'm guessing there's a garbage collection process that runs intermittently and this just happened to fall in that cycle...it periodically jumped up/down to about the previous level again between the 15 and 30 macros tests.) after 15 Campaign panel macros changed

Memory after editing 30 campaign panel macros: after 30 Campaign panel macros changed

I believe I was able to drop the memory usage back to something like 700MB again after double-clicking my bar post-30 campaign macro edits, but I didn't save a file with that name so I can't demonstrate it.

MapTool Info

Desktop (please complete the following information):

Additional context Test Campaign file: 1memtest.zip

RicoTheBold commented 4 years ago

Forgot to mention:

Phergus commented 4 years ago

This happens on both the GM, Selected and Campaign macro panels with the memory being lost for each image button macro opened in the editor.

Clearing the panel does not recover the memory nor does selecting New Campaign from the file menu.

Opening the same macro in the editor and clicking on OK multiple times has the same effect as editing multiple different macros.

The amount lost each time may be related to the image size and/or number of image button macros on the panel.

pizzystrizzy commented 4 years ago

I believe this is related to the fact that for tokens containing many macro buttons with images, there is a significant lag between the time you click and the time they are actually selected.