Complete.Org: Mailing Lists: Archives: freeciv-dev: September 1999:
[Freeciv-Dev] code optimization ideas
Home

[Freeciv-Dev] code optimization ideas

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] code optimization ideas
From: Markus Linnala <maage@xxxxxxxxx>
Date: 22 Sep 1999 14:17:00 +0300
Reply-to: Markus Linnala <maage@xxxxxxxxx>

As you all know freeciv is hopelessly slow at big maps and many
cities and units, even at fastest machines.

Reasons behind this are:
- it iterates over map
- it iterates over cities and tiles / units at or near them
- it iterates over units and tiles / cities at or near them
- some of the functions and means of calculating are not
  optimized

If somebody wants to improve speed a little, here's some
pointers. But I don't think that there is an easy way to speed
up considerably without changing algorithms.

Top 10 functions use most of time.

You should make new function from reinforcements_value &
reinforcements_cost that does the job at find_something_to_kill.
I don't think there is no need to loop map and run
unit_belligerence_basic twice.

Make array of lists of tiles at continets. Make tiles know theis
x and y values. At ai_manage_explorer part 3 there is no need to
loop map as you could iterate just over the continent. You might
want to split ai_manage_explorer before.

Break find_genlist_position in two parts, first part is check if
pos is 0 and second is the rest. Inline the first part or make
it macro. At least 99% of the calls fit to the first part. At
TYPED_LIST_ITERATE might be usefull to test it list has any
items before we start to init iteration etc. You have to make
some counter to count usages to find that out.

Integrate all cases at map.c/other places too where there is
map.tiles+map_adjust_x(x)+y*map.xsize to the one function. Make
it maintain values of the previous call. It is called sometimes
more than 20 times per row with same parameters. Find those.
Inline map_get_tile or make it macro. It is sometimes called
more than 50 million times per turn. Or maybe use static array,
and then you don't have to use multiplication, but dunno if it
is faster.

Units and cities should know where they are ie their tile, as
knowing where they are reduces greatly need to map_get_tile.

At init warmap, it might be more speedier to use memset as it is
to iterate over map item by item.

Check usage of the dangerfunct. Maybe it always returns 0 if
dist is 255 and dist is 255 50% of time.

Split way too big functions at ai to smaller parts. It is way
easier to spot bad spots.

Find ways to locate duplicate use of warmaps.

-- 
//Markus

[Prev in Thread] Current Thread [Next in Thread]