Jump to content

Would Webber's Tree Require a Spider CPU Usage Rework?


Recommended Posts

I'm not incredibly sure how strong the average server is, but I know for certain my usual server doesn't have the power for it. We had 1 Webber walk into base with maybe 30 spiders and the server was hitting yellow. He said it was something to do with the fact we had all our resources on the ground and spiders do some weird check on them? I'm not sure if that's true, but whatever it is ,was definitely hurting the server.

I'm not entirely sure how spiders work or affect CPU usage, I just know they can drain a lot of it. Is there even a way to improve this or is the future Webber tree just guaranteed to bring Yellow and Red servers across the world for awhile?

 

(also I wouldn't mind an explanation on mob brain CPU usage)

1 hour ago, Radicaljoe said:

He said it was something to do with the fact we had all our resources on the ground and spiders do some weird check on them?

they check every item within 2.5 tiles away from them that isn't unreachable (e.g. on 1 of those pedestals poking out of void in ruins, it just being separated from them by a wall or something like that won't make it that way iirc) or in an inventory or a container for being food for eating it every second, so if there were 30 items on the ground within 2.5 tiles away from all spiders and 30 spiders, there were around 900 checks per second    

4 minutes ago, Radicaljoe said:

Ah, yeah that seems like it would stress a server pretty badly. I wonder if the spiders themselves count as items? I know lureplants will eat them like items, so I wonder if they check each other? 

they do i think, so around 1800 checks per second if they all are within 2.5 tiles away from each other    

4 minutes ago, ChintzyGnat said:

Couldn't this be avoided by checking only edible items instead of every item? I'm no coder but what's the purpose of checking every item if it isn't for food?

the check is what's checking if they're food and then making them go eat it if it's, they could make the check more optimized by adding tags of all food types that spiders can eat into the check though, idk why didn't they, ig because 2013 code

13 hours ago, grm9 said:

the check is what's checking if they're food and then making them go eat it if it's, they could make the check more optimized by adding tags of all food types that spiders can eat into the check though, idk why didn't they, ig because 2013 code

They're not the only entity that doesn't do this, but yeah, adding more tags instead of manually checking for most entities would be a massive improvement.

Especially since:

14 hours ago, grm9 said:

they check every item

They check every entity, not just items. With like you said, only stuff in limbo (inventories, containers, some spawners, etc) or things that are "out of reach" (icker preservers, items in the middle of a hole near the ruins) being exempted, so it's even worse than checking every item (including spiders themselves).

Players, structures, trees, walls, whatever, visual effects, whatever, you name it, it's getting checked unless the limbo or out of reach conditions apply.

 

Vanilla:

local EATFOOD_CANT_TAGS = { "INLIMBO", "outofreach" }
local function EatFoodAction(inst)
    local target = FindEntity(inst,
        SEE_FOOD_DIST,
        function(item)
            return inst.components.eater:CanEat(item)
                and item:IsOnValidGround()
                and item:GetTimeAlive() > TUNING.SPIDER_EAT_DELAY
        end,
        nil,
        EATFOOD_CANT_TAGS
    )
    return target ~= nil and BufferedAction(inst, target, ACTIONS.EAT) or nil
end

Modified:

-- add must tag to not bother with non-items
-- this might be unwanted if the possibility of edible non-items is there (from mods, or a future feature), but otherwise it'd help a lot
-- if not adding this, the edible tags below being sent for the search will be enough of a massive improvement already
local EATFOOD_MUST_TAGS = { "_inventoryitem" }

local EATFOOD_CANT_TAGS = { "INLIMBO", "outofreach" }
local function EatFoodAction(inst)
    local item_lifetime_grace = TUNING.SPIDER_EAT_DELAY -- cache
    local target = FindEntity(inst,
        SEE_FOOD_DIST,
        function(item)
            return inst.components.eater:CanEat(item)
                and item:GetTimeAlive() > item_lifetime_grace
                and item:IsOnValidGround() -- check this last due to being the most expensive out of all these
        end,
        EATFOOD_MUST_TAGS,
        EATFOOD_CANT_TAGS,
        inst.components.eater:GetEdibleTags() -- don't bother with entities that don't have any of our edible tags
    )
    return target ~= nil and BufferedAction(inst, target, ACTIONS.EAT) or nil
end

-- if memory is a concern due to amount of spiders, and the performance hit of not caching the edible tags isn't too bad
-- set .cacheedibletags = false for the eater component in the spiders prefab constructor

-- inst.components.eater:CanEat(item) can also technically be removed at that point, but that function could be modified
-- by mods or so to check for things other than tags, so instead maybe a parameter could be added to it to pass that the edible tags
-- were already checked by the search and don't need to be checked again there

I haven't tested this as I just came up with these changes, but it could be a good start.

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...