Speed up for short range chart

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

Post Reply
Y A J
Average
Average
Posts: 15
Joined: Fri Oct 02, 2009 4:10 pm
Location: Laenin, Galaxy 1

Speed up for short range chart

Post by Y A J »

Hi folks,

On my system (2.13 GHz Core 2 Duo), the short range chart is pretty slow (about 40 fps, using 100% CPU). The problem is that drawStartChart calls generateSystemData for every nearby system for every single frame, and collectively that takes an awful lot of work.

What do you think about the following alternative? Instead of recomputing everything every frame, just store the little bit of data for whichever systems are in range, and use the cached values whenever possible (which is almost always, unless the player has moved). That change drops the CPU usage for me to 45% and ups the frame rate to 75 fps (my monitor vsync rate).

I have a patch to GuiDisplayGen.m, but it's a little bit big, so I've put it here:

http://oolite.pastebin.com/f485c4638

Bye for now,
- Yet Another Jameson
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6683
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

It''s going in. Good job Y A J and please check your PMs.
Screet
---- E L I T E ----
---- E L I T E ----
Posts: 1883
Joined: Wed Dec 10, 2008 3:02 am
Location: Bremen, Germany

Re: Speed up for short range chart

Post by Screet »

Y A J wrote:
On my system (2.13 GHz Core 2 Duo), the short range chart is pretty slow (about 40 fps, using 100% CPU).
Thanks for fixing that!!!

What astonishes me is the speed difference - on my Phenom 9500 with 4 x 2.2 GHz it often went down to around 14fps - maybe some oxp's further slow down the process massively?

Anyway, it's the only screen I remember to slow things below vsync rate, so I'm very happy now! :D

Screet
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2483
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Post by Griff »

We should get a little graphic of the 'Milk Tray' man's calling card for Y A J posts, he slips in through the window, leaves behind a patch for the oolite code then ski's off down a snowy mountain side
User avatar
Micha
Commodore
Commodore
Posts: 815
Joined: Tue Sep 02, 2008 2:01 pm
Location: London, UK
Contact:

Post by Micha »

Considering the cache consists of 256 entries anyway, why not just cache the system data for the entire current map for the duration of the gaming session anyway?

ie: something like this in Universe.m:

Code: Select all

static struct saved_system
 	{
		int seed_d, seed_b;
		int tec, eco, gov;
		NSString* p_name;
	} nearby_systems[ 256 ];

struct saved_system * getSysInfo(int x)
{
  if( saved_system[x].seed_d == -1 ) // or a specific isComputed flag
  {
    <compute and store system info>
  }
  return saved_systems[x];
}
Only time you'd need to flush it is on Gal-Jump. This way you'd get the cache bonus everywhere, not just in the local map.
The glass is twice as big as it needs to be.
Y A J
Average
Average
Posts: 15
Joined: Fri Oct 02, 2009 4:10 pm
Location: Laenin, Galaxy 1

Post by Y A J »

another_commander wrote:
It''s going in.
Thanks, a_c!
Micha wrote:
Considering the cache consists of 256 entries anyway, why not just cache the system data for the entire current map for the duration of the gaming session anyway?
Ah, good point. The existing generateSystemData claims to obtain a 80-95% hit rate with its single system cache, so there might not be much scope for improvement, but I'll have a look in case it helps things elsewhere.

Thanks,
- Yet Another Jameson
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Y A J wrote:
Micha wrote:
Considering the cache consists of 256 entries anyway, why not just cache the system data for the entire current map for the duration of the gaming session anyway?
Ah, good point. The existing generateSystemData claims to obtain a 80-95% hit rate with its single system cache, so there might not be much scope for improvement, but I'll have a look in case it helps things elsewhere.

Thanks,
- Yet Another Jameson
With your current patch my FPS rate on that screen rose from about 30 to 100 FPS . And 100 is about the maximum I generally can get so any further improvement won't be so significant.
Great job YAJ :)
User avatar
Micha
Commodore
Commodore
Posts: 815
Joined: Tue Sep 02, 2008 2:01 pm
Location: London, UK
Contact:

Post by Micha »

My suggestion would not improve that screen further; rather, my thinking was that if we reserve that much memory anyway, then we might as well keep all the calculated data and possibly use it elsewhere as well.

Alternatively, reduce the size of the cache - we'll never have 256 systems in the local chart.
The glass is twice as big as it needs to be.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

Micha wrote:
Only time you'd need to flush it is on Gal-Jump. This way you'd get the cache bonus everywhere, not just in the local map.
You're forgetting all the times the system data is changed via script: unless you explicitely flush the cache for the altered system, you'll have out of date info sitting in the cache.

Things that can be altered dynamically by any oxp at any time: system name, government type, population, tech level, etc, etc....
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
Post Reply