Dwarf Fortress Bug Tracker - Dwarf Fortress
View Issue Details
0005971Dwarf FortressDwarf Mode -- Jobs, Eating/Drinkingpublic2012-05-30 03:592014-07-23 12:43
Toady One 
0005971: Fat dwarves eating causes lag.
Wasted CPU can be expected to be on the order of 5-10%.

The lag is caused by the interaction of two factors:

1) When the unit's fat amount crosses a 2500 boundary, its clothing insulation is recomputed.
2) Fat is capped at 1000000, which is divisible by 2500.

The result is that for every unit at 1000000 fat with digestion counter active, it recomputes insulation every frame, because of jitter caused by interaction between +5 from digestion (hits the boundary) and -random from natural consumption (doesn't). This can be very easily worked around by capping at 999999 instead of 1000000.
Set units to 1000000 fat and activate their digestion counter (the one incremented when eating/drinking non-water).
Profiling graph with the problem active (see bottom left):
file:///home/sasha/Games/DF/profiling/log.ab2a.svg [^]
Profiling graph with digestion hacked to use 999999 instead of 1000000 as cap:
file:///home/sasha/Games/DF/profiling/log.ab2b.svg [^]

Also note in those graphs that checking caste flags approaches 8% CPU usage; it is very hard for me to estimate where most of those calls come, but it seems that checks for OPPOSED_TO_LIFE, CRAZED, and other CE_ADD_TAG affected ones amount to at least 50% of that. The simplest way to fix that is probably to cache those in another bitfield in the unit, so that active tag set could be computed simply as (base | added) & ~removed.
No tags attached.
Issue History
2012-05-30 03:59agNew Issue
2012-05-30 04:03agNote Added: 0022787
2014-07-23 12:43Toady OneStatusnew => resolved
2014-07-23 12:43Toady OneFixed in Version => Next Version
2014-07-23 12:43Toady OneResolutionopen => fixed
2014-07-23 12:43Toady OneAssigned To => Toady One

2012-05-30 04:03   
Correct graph links:

http://cloud.github.com/downloads/angavrilov/dfprofile/log.ab2a.svg [^]
http://cloud.github.com/downloads/angavrilov/dfprofile/log.ab2b.svg [^]