Hi, after getting fed up with the slow speed of freeciv in a large game I did some profiling. One thing I noticed is that there are MACROS that use one of their arguments twice. With the change to make the player_index a function call they are not called with a function call as argument instead of an interger. Using the argument twice means the function call is executed twice.
In the server 3% of the total time where spend in map_is_known: [56] 3.0 5.43 12.74 152585010 map_is_known [56] 8.89 0.00 305170020/565345748 player_number [62] 3.85 0.00 305170020/541877534 player_index [103] Notice how player_number and player_index is called twice for every map_is_known? ---[ server/maphand.c ]------------------------------------------------------ /**************************************************************************** Return whether the player knows the tile. Knowing a tile means you've seen it once (as opposed to seeing a tile which means you can see it now). ****************************************************************************/ bool map_is_known(const struct tile *ptile, const struct player *pplayer) { return BV_ISSET(ptile->tile_known, player_index(pplayer)); } ---[ utils/shared.h ]------------------------------------------------------ #define BV_ISSET(bv, bit) \ (_BV_ASSERT(bv, bit), \ ((bv).vec[_BV_BYTE_INDEX(bit)] & _BV_BITMASK(bit)) != 0) ---[ common/player.c ]----------------------------------------------------- /************************************************************************** Return the player index. Currently same as player_number(), paired with player_count() indicates use as an array index. **************************************************************************/ int player_index(const struct player *pplayer) { return player_number(pplayer); } /************************************************************************** Return the player index/number/id. **************************************************************************/ int player_number(const struct player *pplayer) { assert(pplayer); return pplayer - game.players; } ----------------------------------------------------------------------------- Is there any reason BV_ISSET (and similar ones) isn't written as a static inline function? That one macro alone would save 1.5%. Inlining the player_number() and player_index() functions (and other similary trivial and often called functions) would save a lot of time too. Any reason such frequent one-liners aren't declared static inline in the header file? MfG Goswin _______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev