slow autoplay of missing tapes & levels

Found a bug in R'n'D? Report it here!

Moderators: Flumminator, Zomis

Post Reply
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

slow autoplay of missing tapes & levels

Post by filbo »

I have long noticed a slowness in autoplay of certain levelsets. If there are some tapes for a levelset, but not as many as levels exist; or if a levelset's .conf claims to have a certain number of levels (say, 100), but actually has fewer (say, 81) -- then the empty 'playing' of the missing tapes or levels is slow.

For instance, I have a (non-solving) tape for level 0 of dx_dc2classic, but none of the other 99 levels. Running:

$ rocksndiamonds --mytapes -e "autotest dx_dc2classic"

takes 6.05s of realtime; the printing of 99 '(no tape found)' lines is visually slow; while:

$ rocksndiamonds --mytapes -e "autotest dx_dc2classic 0"

takes only 3.08s. And most interestingly,

$ rocksndiamonds --mytapes -e "autotest dx_dc2classic $(seq -s ' ' 1 99)"

takes 0.78s to 'play' 99 missing level tapes, reeling out the 99 '(no tape found)' lines at high speed!

Where did the missing 2.3 seconds disappear to?

After a lot of poking around, I determined that in the 1-level case, InitElementPropertiesEngine() is called 3x, and InitElementGraphicInfo() 2x; in the 100-level case (1 tape + 99 missing), they are called 102 & 101 times. That seems reasonable. But then in the 99-blank-tapes case, they are called 100 & 1 time!

The end of InitElementPropertiesEngine() is:

// this is needed because some graphics depend on element properties
if (game_status == GAME_MODE_PLAYING)
InitElementGraphicInfo();

and I guess `game_status == GAME_MODE_PLAYING` after the end of the level-0 tape.

Should this be fixed by:

- end-of-tape / end-of-level-run code setting `game_status` to some other value?

- InitElementGraphicInfo() setting it to some other value?

- something else?
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: slow autoplay of missing tapes & levels

Post by Holger »

Yes, I think I also noticed this once, but did not investigate it in detail any further. But this reminds me of a speed-up I've added only a short time ago for uploading all tapes to the score server: With a lot of level sets (with or without tapes), it took several minutes to process all level sets. I was able to reduce this to a few seconds by adding a check for existing or non-existing tape, as the code path ran into loading the level before, even if there was no tape, which added a huge execution speed overhead. (See commit e11fa67d.)

So your observations are interesting, and seem to confirm that loading the level (even if there is no tape to play/test) is the cause of the delay. If this only happens when loading the current level (or loading a level manually selected in the main menu), it does not hurt that much, but when quickly processing (and skipping) through lots of levels (with or without tape), it does make a huge speed difference.

I'll have a look at this again. Maybe this can either be handled in a way similar to the above commit, or by just skipping some graphics initialization code that is not needed when auto-testing tapes on the command line.
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: slow autoplay of missing tapes & levels

Post by filbo »

Isn't it wrong for `game_status == GAME_MODE_PLAYING` after tape playback has ended and we're ready to load the next level? It's more like GAME_MODE_PREPARING ...
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: slow autoplay of missing tapes & levels

Post by Holger »

Automatic tape testing just continues with replaying the next tape as soon as a tape is finished, without changing the game mode (as there's no MAINMENU etc. involved. So there's no game mode for "preparing" here, and "InitElementPropertiesEngine()" just checks if the level should be played now to adjust graphics, if needed.

The best solution is probably to check for "headless mode" here, and skip it in that case.

I'll check if this will give a noticeable speed-up, or if there are more bottlenecks for auto-testing to be removed in case of non-existing levels/tapes.
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: slow autoplay of missing tapes & levels

Post by Holger »

OK, I've just extended the check if the tape to play/test/upload exists at all, and skip everything else (especially loading the level) if it does not exist. This gives indeed a huge speed improvement, just as with uploading tapes.

Auto-testing level sets with only a few tapes is much faster now. (See updated branch "master-next-major-release".)
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: slow autoplay of missing tapes & levels

Post by filbo »

Fixed!
Post Reply