Skip to main content
Topic: Performance problem after saving game (Read 3509 times) previous topic - next topic

Performance problem after saving game

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

Re: Performance problem after saving game

Reply #1
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

Re: Performance problem after saving game

Reply #2
(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 ;-) )

Re: Performance problem after saving game

Reply #3
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.

Re: Performance problem after saving game

Reply #4
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

 

Re: Performance problem after saving game

Reply #5
To me, it looks like this bug report can be closed. Other opinions?
Parsley, sage, rosemary, and maggikraut.

Re: Performance problem after saving game

Reply #6
It was fixed. Thanks priss.

I suppose this report can be closed.