The International Simutrans Forum

 

Author Topic: Performance problem after saving game  (Read 2570 times)

0 Members and 1 Guest are viewing this topic.

Offline Amelek

  • *
  • Posts: 70
Performance problem after saving game
« on: January 03, 2010, 12:24:06 PM »
Recent nightlies and revision 2996 seem to have error in saving routines:

Before save game runs ~26 fps (result from display settings)
After saving this decreases to unacceptable ~3 fps
After a while it would return to previous value, doing few fastforward + pause seem to fix this too.

probably, some internal block isn't released after saving
« Last Edit: January 03, 2010, 12:28:38 PM by Amelek »

Offline Amelek

  • *
  • Posts: 70
Re: Performance problem after saving game
« Reply #1 on: January 04, 2010, 09:56:27 PM »
I'm extremely sorry for double posting, but probably nobody wouldn't notice this, as something that looks like patch to this bug is already on SVN.

http://mallorn.ii.uj.edu.pl/~amelek/fixLag.patch

Here is a solution to this bug I written.

It do fixes this bug, but there are some problems:

Old code uses
Code: [Select]
if(last_frame_ms[last_frame_idx]<last_ms) {
realFPS = (32000u) / (last_ms-last_frame_ms[last_frame_idx]);

to calculate fps. This is totally wrong as it refers to ancient (31 steps in past) frame to calculate FPS. Probably that's why there is a 32000 rather then 3200

Now, my patch changes this to
Code: [Select]
if(last_frame_ms[(last_frame_idx+30) % 32]<last_ms) {
realFPS = (3200u) / (last_ms-last_frame_ms[(last_frame_idx+30) % 32]);
what results in about 3 times boost in FPS.This is because old game referred to 32 frames in past, divided by 10. Now this is gone = 3.2 times more fps. But, I guest that this is true FPS value. Thus, game runs 3.2 times faster then it used to, so maybe some other fix is needed. (?)

Second thing is, that this patch, after save, resets last frame ms, so that next loop would miss FPS calculation and instead use fixed umgebung_t::fps value. This isn't probably problem for single player, but may be a bother for multi player if this is used somewhere else.

Edit: come to think about it: from where comes 32000? Oo I though that it's 36000 that would make some sense, but now I see that this is different value. Odd Oo
« Last Edit: January 04, 2010, 10:09:49 PM by Amelek »

Offline Isaac Eiland-Hall

  • Benevolent Dictator
  • Administrator
  • *
  • Posts: 3912
  • Providing hosting for Simutrans projects
    • pc2.io
  • Languages: EN
Re: Performance problem after saving game
« Reply #2 on: January 05, 2010, 08:08:26 AM »
(just a quick note: I judge something like this to be a sufficient exception to double-posting. Mainly it's an hour or two that's the big deal, or 10 posts in a row ;-) )

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10622
  • Languages: De,EN,JP
Re: Performance problem after saving game
« Reply #3 on: January 05, 2010, 09:09:54 PM »
Well frame per second are 1s / time_per_frame.

If I have 32 frames, I have to use 32s / tim_for_32_frames.

And thus for millisecons I have to use 32*1000 / time_for_32_frames_in_milliseconds. Hence: The formula in the program is correct, and a reset_timer() after saving (which I put in after your first posting) should take care of that.

Offline Amelek

  • *
  • Posts: 70
Re: Performance problem after saving game
« Reply #4 on: January 05, 2010, 09:19:06 PM »
Well, old code looks like that:

Code: [Select]
uint32 last_ms = dr_time();
last_frame_ms[last_frame_idx] = last_ms;
last_frame_idx = (last_frame_idx+1) % 32;
if(last_frame_ms[last_frame_idx]<last_ms) {
realFPS = (32000u) / (last_ms-last_frame_ms[last_frame_idx]);
}
else {
realFPS = umgebung_t::fps;
simloops = 60;
}

if(last_frame_ms[last_frame_idx]<last_ms) { this probably was meant to refer to previous frame, but due to last_frame_idx = (last_frame_idx+1) % 32; in previous line actually refers to first recorded and still remaining frame. As frames are not updated during save, this frame refers to really ancient time (like 20 seconds in past), resulting in 0 FPS. As RealFPS is related with refreshing of last_frame_ms, game takes hard time to redo it and as result lags for quite a time.

Probably, this would still be good, as long as saving routine (or other long-blockers) would reset entire last_frame_ms table. Map enlarger do so
Code: [Select]
// make timer loop invalid
for( int i=0;  i<32;  i++ ) {
last_frame_ms[i] = 0x7FFFFFFFu;
last_step_nr[i] = 0xFFFFFFFFu;
}
last_frame_idx = 0;
for a reason (?)

Your reset_timer() is indeed required, but unfortunately, it doesn't fix the bug

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4869
  • Languages: EN, DE, AT
Re: Performance problem after saving game
« Reply #5 on: January 17, 2010, 08:28:08 AM »
To me, it looks like this bug report can be closed. Other opinions?

Offline Amelek

  • *
  • Posts: 70
Re: Performance problem after saving game
« Reply #6 on: January 17, 2010, 08:56:12 AM »
It was fixed. Thanks priss.

I suppose this report can be closed.