Cleanup and hoping to increase performance
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
41 posts
• Page 1 of 3 • 1, 2, 3
Cleanup and hoping to increase performance
by Sloth » 28 Jul 2012, 21:53
You might have noticed that i commited some risky code changes in the last couple of days. The reason is that forge has become rather slow on one of my two computers (and some users have reported forge to behave more sluggishly) and i want to see which part is responsible for this.
Here are my results so far:
1. The AI is not responsible for big slowdowns (i can completey shut off playSpellAbilities and it won't change much).
2. Reducing heap size has lots of potential and could speed up loading times and maybe slowdowns on some systems. The biggest chunk by far is the card class, because two copies of each card are loaded on start up (one "small" object for the deck editor and a "full" object for the game). Just changing a few ArrayLists to start as null pointers instead of empty lists reduced the heap space needed by about 2%.
3. In the end, i'm confident that the GUI is responsible for the biggest slowdowns. Removing a few of the "updateObservers" calls made forge a little more fluid already (on my slow computer at least) and i notice a little pause before the start of every animation (cards moving into hand for example).
I'm just a hobby programmer so maybe i'm missing the most important things here. Is there anything you can add to this topic that might help?
Here are my results so far:
1. The AI is not responsible for big slowdowns (i can completey shut off playSpellAbilities and it won't change much).
2. Reducing heap size has lots of potential and could speed up loading times and maybe slowdowns on some systems. The biggest chunk by far is the card class, because two copies of each card are loaded on start up (one "small" object for the deck editor and a "full" object for the game). Just changing a few ArrayLists to start as null pointers instead of empty lists reduced the heap space needed by about 2%.
3. In the end, i'm confident that the GUI is responsible for the biggest slowdowns. Removing a few of the "updateObservers" calls made forge a little more fluid already (on my slow computer at least) and i notice a little pause before the start of every animation (cards moving into hand for example).
I'm just a hobby programmer so maybe i'm missing the most important things here. Is there anything you can add to this topic that might help?
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Cleanup and hoping to increase performance
by Chris H. » 28 Jul 2012, 22:05
Forge's findbugs report has a few performance type errors and fixing them may provide some relief?
-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
Re: Cleanup and hoping to increase performance
by friarsol » 29 Jul 2012, 03:00
I think you are definitely right the UI is part of the main causes to the slowdowns. But just playing a quick quest game it looks like the power toughness values take a few phases before they update. The AI cast a Murkfiend Liege and three phases later all his creatures changed P/T. And when I destroyed the Liege it took a few more phases before they reset.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: Cleanup and hoping to increase performance
by Max mtg » 29 Jul 2012, 10:34
Hey, Sloth
I have removed some shit left by Braids (use of Generators to iterate over filesystem), some exessive arraylists creation and turned card parsing code into a little state machine. Got -25% heap usage.
The other big piece of improvements is really about using the heavy Card class only when neccesary - never use it in deck editors or other deck generator. If you stop Forge at the menu screen there are already 22 thousand instances of forge.Card ... while there should be zero.
I have removed some shit left by Braids (use of Generators to iterate over filesystem), some exessive arraylists creation and turned card parsing code into a little state machine. Got -25% heap usage.
The other big piece of improvements is really about using the heavy Card class only when neccesary - never use it in deck editors or other deck generator. If you stop Forge at the menu screen there are already 22 thousand instances of forge.Card ... while there should be zero.
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: Cleanup and hoping to increase performance
by Sloth » 29 Jul 2012, 11:50
It's good to have some help Max. With r16353 i get two compile errors though: It seems that CardFactory was used as iterable in two places.Max mtg wrote:Hey, Sloth
I have removed some shit left by Braids (use of Generators to iterate over filesystem), some exessive arraylists creation and turned card parsing code into a little state machine. Got -25% heap usage.
The other big piece of improvements is really about using the heavy Card class only when neccesary - never use it in deck editors or other deck generator. If you stop Forge at the menu screen there are already 22 thousand instances of forge.Card ... while there should be zero.
I've also noticed that random deck generation is now buggy (colors don't match with basic lands anymore).
EDIT: Most of the time generate random deck will fail.
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Cleanup and hoping to increase performance
by Chris H. » 29 Jul 2012, 12:02
Sloth wrote:With r16353 i get two compile errors though: It seems that CardFactory was used as iterable in two places.
Can only iterate over an array or an instance of java.lang.Iterable
GuiDownloadPicturesLQ.java
/ForgeSVN/src/main/java/forge/gui/download
line 71
Can only iterate over an array or an instance of java.lang.Iterable
GuiMigrateLocalMWSSetPicturesHQ.java
/ForgeSVN/src/main/java/forge/gui
line 496
-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
Re: Cleanup and hoping to increase performance
by Sloth » 29 Jul 2012, 12:10
The mana cost overlays also behave flakey now.
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Cleanup and hoping to increase performance
by friarsol » 29 Jul 2012, 15:01
When we're preloading card images, could we keep track of the images that weren't found instead of needing to go back through CardFactory in the Download Pictures functions?
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: Cleanup and hoping to increase performance
by Max mtg » 29 Jul 2012, 20:42
That's strange... looks like collection.tounmodifiablesomething does not copy the collection. Ok, i'll find a method - maybe replacing the arraylist with pure array will improve the manaparser perf. Thanks for the bug report. 
Sol, I am not sure. The actual system has an advantage that it can catch graphics as you copy it into the right folder. You'll have to reload the app to have that file list built for actual fs state, not the one by the moment application has started.
The real challenge is to have cardfactory load cards by request. It should have card-printed always ready, and Card instances will all the spellabilities and friggers to become lazily loaded. I am sure that will release another hundred of megabytes of heap

Sol, I am not sure. The actual system has an advantage that it can catch graphics as you copy it into the right folder. You'll have to reload the app to have that file list built for actual fs state, not the one by the moment application has started.
The real challenge is to have cardfactory load cards by request. It should have card-printed always ready, and Card instances will all the spellabilities and friggers to become lazily loaded. I am sure that will release another hundred of megabytes of heap
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: Cleanup and hoping to increase performance
by friarsol » 30 Jul 2012, 02:33
Ok, it looks like the mana pool count isn't updating until you finish paying the whole cost right now, which is terrible UI.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: Cleanup and hoping to increase performance
by Sloth » 30 Jul 2012, 20:20
This should be working now. I still removed the UpdateObserver call from clearManaPool, because that only happens when priority shifts. Thanks for checking sol.friarsol wrote:Ok, it looks like the mana pool count isn't updating until you finish paying the whole cost right now, which is terrible UI.
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Cleanup and hoping to increase performance
by Max mtg » 30 Jul 2012, 21:17
I have just removed a "creating card objects step" from loading sequence. The game still compiles and works! Was that step needed at all?
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: Cleanup and hoping to increase performance
by friarsol » 30 Jul 2012, 21:30
I believe we had a discussion at one point regarding this (before CardPrinted objects existed) and determined it was better to load card objects in the startup script than loading faster and then needing to wait again for Card objects to be created for opening the deck editor or starting a game. It does make more sense only to load Card Objects before a match (now that CardPrinted objects exist), and we'll only need to have a few hundred full Card objects in memory at a time, instead of 11k all of the time.Max mtg wrote:I have just removed a "creating card objects step" from loading sequence. The game still compiles and works! Was that step needed at all?
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: Cleanup and hoping to increase performance
by Max mtg » 30 Jul 2012, 21:52
Look, when "preloading card images" runs, all the Card objects are already created once. So the second run was absolutely useless - it collected all copies into a single list for an unknown by now purpose.friarsol wrote:I believe we had a discussion at one point regarding this (before CardPrinted objects existed) and determined it was better to load card objects in the startup script than loading faster and then needing to wait again for Card objects to be created for opening the deck editor or starting a game. It does make more sense only to load Card Objects before a match (now that CardPrinted objects exist), and we'll only need to have a few hundred full Card objects in memory at a time, instead of 11k all of the time.
I am already working on code that would create Card objects from CardPrinted objects. And, yes, getCard(String, ...) will be removed from cardfactory interface
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: Cleanup and hoping to increase performance
by Max mtg » 30 Jul 2012, 23:08
ok, let's see: r16375 has implemented forge.Card on-demand creation.
Post bug reports here
Upd: a picture to compare.
Upd2: I've only optimized the startup to reduce heap size. The other source of complaints (ai and gui slowdowns) are yet to be fixed
Post bug reports here
Upd: a picture to compare.
Upd2: I've only optimized the startup to reduce heap size. The other source of complaints (ai and gui slowdowns) are yet to be fixed
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
41 posts
• Page 1 of 3 • 1, 2, 3
Who is online
Users browsing this forum: No registered users and 48 guests