Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] Re: (PR#9947) insane inefficiency in packet sending
Home

[Freeciv-Dev] Re: (PR#9947) insane inefficiency in packet sending

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#9947) insane inefficiency in packet sending
From: "Raimar Falke" <hawk@xxxxxxxxxxxxxxxxx>
Date: Sun, 5 Sep 2004 19:53:26 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9947 >

On Sat, Sep 04, 2004 at 10:43:07PM -0700, Jason Short wrote:
> 
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=9947 >
> 
> packets.c:148
> 
>        pc->compression.queued_packets = 
> fc_realloc(pc->compression.queued_packets, new_size);
> 
> because a realloc is done every time a packet is sent, this makes 
> sending packets O(n^2).
> 
> For instance if you have Apollo's, at the end of the turn you'll receive 
> 4000 packets of (maybe) 5 bytes on average.  This means 4000 reallocs of 
> average size 10,000.  That's 40 megabytes of memcpying.
> 
> Hopefully you're not playing on a 200x100 map.  Because that means 5x as 
> many packets and 25x as much memcpying.
> 
> People complain about server speeds.  But I suspect fixing this one line 
> would have a bigger effect than hours of trying to figure out which 
> functions to inline.  Of course it won't show up in any autogame timing 
> since no packets are sent out.

Who said that realloc copies the memory? If the libc implementiotion
reserves memory behind the initial requested space and so allow it to grow,
there will be no copying. Also not ethat virtual memory is cheap. You can
reserve quite a large amount of virtual memory space after an allocation.
For a 32 bit system I (as a libc implementor) could choose for example
reserved space = Max(1mb, requested size*10).

        Raimar




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