Skip to main content
Topic: [patch] less calls of INT_CHECK in simhalt.cc (Read 5815 times) previous topic - next topic

[patch] less calls of INT_CHECK in simhalt.cc

According to a profile of prissi, haltestelle_t::rebuild_destination consumes much time due to many calls of INT_CHECK. This patch will reduce this calls.

Re: [patch] less calls of INT_CHECK in simhalt.cc

Reply #1
??? This should not consume much time at all ???

Re: [patch] less calls of INT_CHECK in simhalt.cc

Reply #2
But according to your profile, it comsumes more time, then the routine itself:
Code: [Select]
[19]     8.5    0.22   19.87    1181         haltestelle_t::rebuild_destinations() [19]
                5.10   12.70 1878971/14080882     interrupt_check() <cycle 1> [483]
                0.15    0.00 3121383/54706884     quickstone_tpl<simline_t>::is_bound() const [88]
                0.01    0.05 9753879/11926653     schedule_t::get_count() const [414]
                0.05    0.00 7874908/292124749     quickstone_tpl<haltestelle_t>::operator==(quickstone_tpl<haltestelle_t> const&) const [95]
                0.05    0.00 6898686/39292142     quickstone_tpl<convoi_t>::operator->() const [223]

Re: [patch] less calls of INT_CHECK in simhalt.cc

Reply #3
Just be sure it's called often enough to let the sync steps be executed smoothly.

Re: [patch] less calls of INT_CHECK in simhalt.cc

Reply #4
The total time contains also the time needed for doing an actual sync_step, i.e. redrawing the map etc. The log above shows that the routine itself cost only 0.17s or less than 0.07%.

Re: [patch] less calls of INT_CHECK in simhalt.cc

Reply #5
Yes, of course. And I think 1.8m calls of INT_CHECK is too much, if the routine needs only 0.17s.

Re: [patch] less calls of INT_CHECK in simhalt.cc

Reply #6
Well, without those calls the screen updates would be much less smooth.

Simutrans has two loops, one does the step, events etc. The other is invoked (whenever it is save) by INT_CHECK() which check if the time between two frames has p****ed and either than starts an update loop iteration or returns otherwise. Not calling INT_CHECK() will just make the game more jitery. And since it consumer itself only 0.17s time or less than 0.06% one should do INT_CHECK() not too seldomly.

Re: [patch] less calls of INT_CHECK in simhalt.cc

Reply #7
Prissi,

that's very interesting information about how the game works :-) Tell me - which one of step() and sync_step() is the one called by INT_CHECK()? Or am I getting confused between two different aspects of the threading system?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Re: [patch] less calls of INT_CHECK in simhalt.cc

Reply #8
No, sync_step is most often called by int_check. (In fast forward, things are different, but we ignore this here.)

Re: [patch] less calls of INT_CHECK in simhalt.cc

Reply #9
Very interesting...
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Re: [patch] less calls of INT_CHECK in simhalt.cc

Reply #10
And since it consumer itself only 0.17s time or less than 0.06% one should do INT_CHECK() not too seldomly.
I didn't get this.

And please note, that in this profile rebuild_destinations was only called during loading. IMHO a call of INT_CHECK everytime a lineless vehicle is found, is too much. And if there are no lineless vehicles, this function won't call INT_CHECK anymore...

Re: [patch] less calls of INT_CHECK in simhalt.cc

Reply #11
Int check itself is verz fast. However, from time to time, it will actually does a redraw, and those is the value in front, because it shows the accumulated time. Forget this, just have a look at the first part, where the time consumed by all functions is listened. And here for 300s CPU time 0.17s are due to int_check - neglible.

Re: [patch] less calls of INT_CHECK in simhalt.cc

Reply #12
Simutrans initially had a main program loop and a interrupt routine, which was supposed to be called every 20ms or so.

It turned out that it is hard to handle vehicle movement and display in the interrupt routine, because it might be called any time, even in the middle of executing what appears to be one statement in C++ and therefore operates on inconsistent data).

I changed the hardware driven interrupts to the current mechanism then. The program calls INT_CHECK() frequently, but in places that are safe to be interrupted, and the check routine checks if it's time to call the real interrupt routine.

Just to explain why this is called INT_CHECK, it means "check if it time to interrupt the main loop now".