Skip to content

Huge performance improvement easily possible #86

@TheEt1234

Description

@TheEt1234

The areas:canInterract function uses minetest.check_player_privs without caching the result, this function is put into core.is_protected

This means, that, if there were 500 core.is_protected calls per step, it would call minetest.check_player_privs 500 times wastefully, this is not ideal

Storing the result dramatically increases the performance of core.is_protected

1st test: without the modification
Test code used: //lua local t0 = os.clock(); for i=1,1000000 do core.is_protected(vector.new(0,0,0), "the entity") end; core.debug(os.clock() - t0)
Time: 36.27 seconds

2nd test:
Modification used:
areas/api.lua line 98, function is incomplete

local priv_cache = {}
core.register_globalstep(function()
	priv_cache = {}
end)
-- Checks if the area is unprotected or owned by you
function areas:canInteract(pos, name)
	if priv_cache[name] == true then
		return true
	elseif priv_cache[name] == nil then
		priv_cache[name] = minetest.check_player_privs(name, self.adminPrivs)
		if priv_cache[name] then
			return true
		end
	end

Test code used: //lua local t0 = os.clock(); for i=1,1000000 do core.is_protected(vector.new(0,0,0), "the entity") end; core.debug(os.clock() - t0) (the same)
Time: 3.828 seconds

a 10x improvement (hehe proud of myself!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions