pandorabox-io / pandorabox.io

Pandorabox infrastructure code
https://pandorabox.io
31 stars 4 forks source link

Expensive "minetest.get_objects_inside_radius()" calls #544

Closed BuckarooBanzay closed 4 years ago

BuckarooBanzay commented 4 years ago

The minetest.get_objects_inside_radius() call is an O(n) operation where "n" is the amount of ServerActiveObjects currently active.

Method: https://github.com/minetest/minetest/blob/add68369a59af90f8b4203b53695521c6d657d6b/src/server/activeobjectmgr.cpp#L114-L128

void ActiveObjectMgr::getObjectsInsideRadius(const v3f &pos, float radius,
        std::vector<ServerActiveObject *> &result,
        std::function<bool(ServerActiveObject *obj)> include_obj_cb)
{
    float r2 = radius * radius;
    for (auto &activeObject : m_active_objects) {
        ServerActiveObject *obj = activeObject.second;
        const v3f &objectpos = obj->getBasePosition();
        if (objectpos.getDistanceFromSQ(pos) > r2)
            continue;

        if (!include_obj_cb || include_obj_cb(obj))
            result.push_back(obj);
    }
}

To the left: around 5'000 objects active, to the right: server restart with less than 1'000 objects:

Solutions

TBD :shrug:

Digtron disable entity/player damage at runtime

/lua digtron.damage_creatures = function() end

Related

BuckarooBanzay commented 4 years ago

Maybe related:

The "ServerActiveObject" count does not decrease over the server-runtime:

gpcf commented 4 years ago

same issue at LF.

BuckarooBanzay commented 4 years ago

I've decided to test what happens if the static_save was true for the signs_lib entities here: https://github.com/pandorabox-io/pandorabox_custom/commit/5d0c826eb670cc91b109f0b5bfcbd869e7599bc2

Deployed it on the test-server and letting it run a little, so far the entities seem to unloading and loading properly to/from the map without being activated all the time.

Next (possible) step: yet another caching layer, this time for minetest.get_objects_inside_radius. hook into on_step, cache entites per mapblock and flush periodically if not called for a while...

BuckarooBanzay commented 4 years ago

closing this, static_save = true on the signs entity prevents the mass of SAO's (well, the core-issue is not solved but this is good enough...)