Default almost all node meta fields to private.

Trying to isolate server performance issues, it was pointed out
that clients are spending a LOT of time receiving and rebuilding
mapblock meshes, and that updating node meta triggers this, even
when that meta is not relevant to the rendering of nodes.

Rubenwardy added a suggestion to change this in the engine:
	https://github.com/minetest/minetest/issues/10127
This patch implements this suggestion at the game level, since
in NodeCore's case we already were making the assumption that
nearly all metadata fields were private.
This commit is contained in:
Aaron Suen 2020-06-30 18:19:49 -04:00
parent cf799989b3
commit b4c72c9b2c
2 changed files with 36 additions and 0 deletions

View File

@ -81,6 +81,7 @@ end
include("compat_vector")
include("issue9043")
include("nodemetahack")
include("util_misc")
include("util_hookmeta")

View File

@ -0,0 +1,35 @@
-- LUALOCALS < ---------------------------------------------------------
local getmetatable, minetest, pairs
= getmetatable, minetest, pairs
-- LUALOCALS > ---------------------------------------------------------
local publicfields = {
formspec = true,
infotext = true
}
local function hook(meta)
for k, v in pairs(meta) do
if k:sub(1, 4) == "set_" then
meta[k] = function(data, name, ...)
if not publicfields[name] then
data:mark_as_private(name)
end
return v(data, name, ...)
end
end
end
end
local rawmeta = minetest.get_meta
function minetest.get_meta(...)
local raw = rawmeta(...)
if raw then
local meta = getmetatable(raw)
if meta then
hook(meta)
minetest.get_meta = rawmeta
end
end
return raw
end