mesecons
mesecons copied to clipboard
Remove some unneeded memory allocation
Overview
This PR does three things:
- Clean up the basic info getters like
mesecon.get_conductor
. - Speed up the functions for finding node links, remove unnecessary allocations.
- As far as I can tell there can only be one linking rule between two nodes, so the functions have been simplified.
- The inverted function now returns the actual rule, not the inverted rule.
- Remove unnecessary node copies.
- Components in the modpack with rule getter functions are passed non-copied nodes. External components can get non-copied nodes as well by putting the
rule_node_nocopy
key in their definitions.
- Components in the modpack with rule getter functions are passed non-copied nodes. External components can get non-copied nodes as well by putting the
Benchmarks
I used the benchmarks from https://github.com/minetest-mods/mesecons/pull/578. Keep in mind that reducing garbage collection load may also increase the performance of code outside mesecons.
Long line of diodes
Before: 0.11s After: 0.10s (probably within margin of error)
Block of wires
I turned the block on and off 10 times.
Before: 1.7s After: 0.8s
256 byte memory bank
Before: 1.5s After: 1.3s
Tests
I've done manual testing and things work. The tests from https://github.com/minetest-mods/mesecons/pull/605 also pass.
Perhaps someone with the right privilege can run a search of ContentDB for mods using rules_link_rule_all
and rules_link_rule_all_inverted
. I know lwwires uses them. If they are used by many external mods, I will provide new implementations of them for compatibility with these mods.
https://content.minetest.net/zipgrep/43bc7f2d-403d-4bc4-84bf-3ba524da579d/
Thanks. It looks like lwwires is the only one.
I decided to reimplement the functions regardless.
By the way, this code could be simplified and sped up a bit if it were assumed that the functions which return rules do not modify the node tables passed to them. This assumption is not the norm in the Minetest API, but it seems realistically true.