[crossfire] Proposal: retire MAX_OBJECTS and object allocator

Mark Wedel mwedel at sonic.net
Thu Mar 12 00:18:20 CDT 2020


On 3/11/20 11:08 AM, Kevin Zheng wrote:
> On 3/10/20 9:56 PM, Mark Wedel wrote:
>>   Not sure if still the case, but at one time, performance of allocating
>> thousands of new objects individually increased lag (when loading new
>> maps).  So doing it in blocks of 500 or whatever was faster.  At one
>> point I had put in option to do individually allocation, simply for the
>> reason above - if using a memory debugger, that block of objects failed
>> to work.
> 
> Allocating one object at a time does make mapfile_load() slower (all
> numbers in us):
> 
> x CF Object Allocator
> + 1 object per calloc()
> +----------------------------------------------------------------------+
> |                  x        +                                          |
> |x x    x          x  x*x  x+           +      + + +     +       +    +|
> |      |_________A_M______|   |_______________A_M_____________|        |
> +----------------------------------------------------------------------+
>      N           Min           Max        Median           Avg        Stddev
> x  10         16154         17814       17309.5       17148.7     579.95633
> +  10         17560         20576         19169       19021.9     1033.7963
> Difference at 95.0% confidence
>          1873.2 +/- 787.548
>          10.9233% +/- 4.71741%
>          (Student's t, pooled s = 838.178)
> 
> This measurement was made with n=10 loading /world/world_105_115 with a
> warm disk cache, with a newly started server each time so that memory
> fragmentation hasn't occurred. Time elapsed was measured with a
> monotonic clock.
> 
> It looks like 1-object-per-alloc increases the median by 2 ms. For tiled
> world maps, at worse case 5 maps are loaded at a time, for a total
> additional latency of 10 ms, or about a 11% increase.

  I thought it was be slower, but for modern hardware, that is not very much (going back to the system that had 16 megs of memory, its CPU also run at 25 mhz I think, so ignoring architectural differences, still clearly a lot faster).  Given those old system were maybe 100 times slower, that mean loading the map would take 200 ms, and given tick time hasn't really changed, that means lag.

  However, even in current architecture, this really isn't a problem - since objects are never freed, eventually the game gets to a point where it should enough have objects on the free list that it doesn't need to allocate objects very often.  So after the server first starts up, things may be sort of slow until it sort of reaches that point.



More information about the crossfire mailing list