FS#423 - Improved loading causes high CPU use with long trains

Attached to Project: OpenTTD
Opened by Danny (Danny) - Wednesday, 29 November 2006, 04:41 GMT
Last edited by Remko Bijker (Rubidium) - Friday, 09 March 2007, 08:53 GMT
Type Bug
Category Core
Status Closed
Assigned To KUDr (KUDr)
Operating System All
Severity Medium
Priority Normal
Reported Version Bridge branch (dev)
Due in Version 0.6.0
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


1. A test with 40 trains, each 100 cars taking passengeres between 2 stations used between 10 & 20 % cpu and caused the game to jolt every couple of secconds.
This is occuring in the attached saved game.
Turning 'improved loading algorithm' off reduced cpu to 0% and things ran normally.

The config attached was used to create the game, but I have altered some of the YAPF settings in game which may assert with revisions before ~725x.

2. This is not confirmed, but I am suspicious that the rating calculations do not reach 100% when they should when using improved loading.
This task depends upon

Closed by  Remko Bijker (Rubidium)
Friday, 20 April 2007, 08:00 GMT
Reason for closing:  Fixed
Additional comments about closing:  In r9683.
Comment by Danny (Danny) - Thursday, 30 November 2006, 04:16 GMT
It's trunk, not bridge branch - my mistake.
I'll take a look at it & see if I can sus out the profiler thing.
Comment by Danny (Danny) - Thursday, 30 November 2006, 08:14 GMT
I couldn't run the profiler since I've only got MSVC Pro at the mo. Anyway, I think the problem is that for each car, it checks each other car or more to see if it should load or not - LoadWait(). This may be ok with 10 cars, but 100 cars probably does 100*100 checks.
If I knew enough C I would setup a queue of vehicle references for each cargo type at the station. Trains which needed to wait for cargo would add their cars to the appropriate queue, and wait. When cargo arrived at the station, it would be transfered to the vehicles in the queue. This way no looping or checking needs to be done, and it would be easier to modify the loading order for any new features.
Maybe some other time, or maybe it's already done in the MiniN, but I've had my fill of C for now.
Comment by Darkvater (Darkvater) - Thursday, 07 December 2006, 16:05 GMT
Confirmed (CPU usage). VS Profiler says the following:
LoadWait 46.083 46.083 847 847

o_O using 46% of the CPU time...good, very good...