It is currently 20 Jun 2013, 04:13
   
Text Size

Cleanup and hoping to increase performance

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, moomarc, DennisBergkamp, Rob Cashwalker, Chris H., CCGHQ Admins

Cleanup and hoping to increase performance

Postby 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?
--Sloth, Supreme Bug Squasher
User avatar
Sloth
Programmer
 
Posts: 3082
Joined: 23 Jun 2009, 19:40
Has thanked: 102 times
Been thanked: 437 times

Re: Cleanup and hoping to increase performance

Postby Chris H. » 28 Jul 2012, 22:05

Forge's findbugs report has a few performance type errors and fixing them may provide some relief?
User avatar
Chris H.
Forge Moderator
 
Posts: 5743
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Lion
Has thanked: 510 times
Been thanked: 343 times

Re: Cleanup and hoping to increase performance

Postby 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.
--Sol, Rules Lawyer

Post a Useful Bug Report
friarsol
Programmer
 
Posts: 4218
Joined: 15 May 2010, 04:20
Has thanked: 70 times
Been thanked: 324 times

Re: Cleanup and hoping to increase performance

Postby 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.
Attachments
forge-calls.png
Calls by the moment main menu is shown
Mallorca rocks.
Max mtg
Programmer
 
Posts: 1489
Joined: 02 Jul 2011, 14:26
Has thanked: 122 times
Been thanked: 251 times

Re: Cleanup and hoping to increase performance

Postby Sloth » 29 Jul 2012, 11:50

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.
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.

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, Supreme Bug Squasher
User avatar
Sloth
Programmer
 
Posts: 3082
Joined: 23 Jun 2009, 19:40
Has thanked: 102 times
Been thanked: 437 times

Re: Cleanup and hoping to increase performance

Postby 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
User avatar
Chris H.
Forge Moderator
 
Posts: 5743
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Lion
Has thanked: 510 times
Been thanked: 343 times

Re: Cleanup and hoping to increase performance

Postby Sloth » 29 Jul 2012, 12:10

The mana cost overlays also behave flakey now.
--Sloth, Supreme Bug Squasher
User avatar
Sloth
Programmer
 
Posts: 3082
Joined: 23 Jun 2009, 19:40
Has thanked: 102 times
Been thanked: 437 times

Re: Cleanup and hoping to increase performance

Postby 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?
--Sol, Rules Lawyer

Post a Useful Bug Report
friarsol
Programmer
 
Posts: 4218
Joined: 15 May 2010, 04:20
Has thanked: 70 times
Been thanked: 324 times

Re: Cleanup and hoping to increase performance

Postby 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
Mallorca rocks.
Max mtg
Programmer
 
Posts: 1489
Joined: 02 Jul 2011, 14:26
Has thanked: 122 times
Been thanked: 251 times

Re: Cleanup and hoping to increase performance

Postby 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.
--Sol, Rules Lawyer

Post a Useful Bug Report
friarsol
Programmer
 
Posts: 4218
Joined: 15 May 2010, 04:20
Has thanked: 70 times
Been thanked: 324 times

Re: Cleanup and hoping to increase performance

Postby Sloth » 30 Jul 2012, 20:20

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.
This should be working now. I still removed the UpdateObserver call from clearManaPool, because that only happens when priority shifts. Thanks for checking sol.
--Sloth, Supreme Bug Squasher
User avatar
Sloth
Programmer
 
Posts: 3082
Joined: 23 Jun 2009, 19:40
Has thanked: 102 times
Been thanked: 437 times

Re: Cleanup and hoping to increase performance

Postby 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?
Mallorca rocks.
Max mtg
Programmer
 
Posts: 1489
Joined: 02 Jul 2011, 14:26
Has thanked: 122 times
Been thanked: 251 times

Re: Cleanup and hoping to increase performance

Postby friarsol » 30 Jul 2012, 21:30

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?
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.
--Sol, Rules Lawyer

Post a Useful Bug Report
friarsol
Programmer
 
Posts: 4218
Joined: 15 May 2010, 04:20
Has thanked: 70 times
Been thanked: 324 times

Re: Cleanup and hoping to increase performance

Postby Max mtg » 30 Jul 2012, 21:52

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.
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.

I am already working on code that would create Card objects from CardPrinted objects. And, yes, getCard(String, ...) will be removed from cardfactory interface
Mallorca rocks.
Max mtg
Programmer
 
Posts: 1489
Joined: 02 Jul 2011, 14:26
Has thanked: 122 times
Been thanked: 251 times

Re: Cleanup and hoping to increase performance

Postby 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
Attachments
forge-card-ondemand.png
the current times taken
Mallorca rocks.
Max mtg
Programmer
 
Posts: 1489
Joined: 02 Jul 2011, 14:26
Has thanked: 122 times
Been thanked: 251 times

Next

Return to Developer's Corner

Who is online

Users browsing this forum: Bing [Bot], squee1968 and 1 guest


Who is online

In total there are 3 users online :: 2 registered, 0 hidden and 1 guest (based on users active over the past 10 minutes)
Most users ever online was 177 on 10 Oct 2011, 16:37

Users browsing this forum: Bing [Bot], squee1968 and 1 guest

Login Form