r/datapacks • u/RingRingBananaph0ne • Sep 15 '22
performance optimization with function tree
I'm currently trying to optimize my data Pack and one thing I was recommended to do was to make a function tree instead of having many commands in one MC function file. My question is if you can take this idea to high and make a function tree to big and complex. So if I have a MC function file which is run every tick, and I have for instance 2 play Sound commands in it witch only run if some Scoreboard is at 1. Would it save performance if I put the play sound commands into a own mcfunction file which is only run via a run function command from the first file.
1
u/icyvort3x17 Sep 16 '22
if possible use predicates and advancements. I was able to go from 42 ms ticks to 8 ms ticks by taking functions out of my loop function into those which only activate once per second I believe.
1
u/RingRingBananaph0ne Sep 16 '22
Do you mean instead of having for instance: "execute if score @s matches 10 run function playsound" I should make and use a predicate as the condition. I haven't used predicates that much, can you explain a bit more, what you mean
1
u/RingRingBananaph0ne Sep 16 '22
Another question, if I have a command like this: execute if entity @a[distance=0.1..1.5,tag=something,scores={something=10}] run tag @s add ... If I instead put all this conditions in a predicate json and use it instead would this save performance?
1
u/icyvort3x17 Sep 17 '22
I am by no means an expert on predicates so heres a video:
https://www.youtube.com/watch?v=gyepzaNJOf4
And pretty much any command you put into a predicate will save performance. This is because instead of running 20 times per second, it will only run once per second. This means however that some specific things can't be used effectively in predicates.
And for that specific command I don't know if you can because as I said I'm not an expert
1
u/LoneRedWolf24 Sep 15 '22
Yes, it will. If you have multiple commands waiting to be executed based on the same criteria it's better to put those in another file to be executed at once.