From 723cb5723cb843aaf9c4571df4d1a381a6e20fa3 Mon Sep 17 00:00:00 2001 From: themodernhakr Date: Tue, 25 Mar 2025 10:42:16 -0500 Subject: [PATCH] vault backup: 2025-03-25 10:42:16 --- Minecraft Datapacking/When Two Macros are Faster than One.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Minecraft Datapacking/When Two Macros are Faster than One.md b/Minecraft Datapacking/When Two Macros are Faster than One.md index d535725..ff3b97c 100644 --- a/Minecraft Datapacking/When Two Macros are Faster than One.md +++ b/Minecraft Datapacking/When Two Macros are Faster than One.md @@ -38,7 +38,7 @@ In mcfunction, this is not so straightforward. Macros would make this really cle ```vb function test_namespace:search_array {keyword: "entry500"} ``` -Unfortunately, macros come with a performance hit. A more performant method, albeit less elegant, is to store the keyword in NBT storage prior to calling the function. The storage can be removed after the function is run: +Unfortunately, macros come with a performance hit. In this particular situation, we can bypass macros altogether. While it's less elegant, it is more performant to store the keyword in NBT storage prior to calling the function. The storage can be removed after the function is run: ```vb data modify storage test_namespace:test_namespace temp.keyword set value 'entry500' function test_namespace:search_array @@ -47,7 +47,7 @@ data remove storage test_namespace:test_namespace temp.keyword ``` Once the entry is found, it is stored in the `temp.result` storage, which can then be consumed by another function. -Now for the logic to do the actual array searching... +Now for the logic to do the actual array searching. Here, the performance hit of running macros is worth it as the alternative involves a massive number of commands to manually iterate over an array. As we'll see later when benchmarking functions, manual iteration is *really* slow. # one macro Macros allow us to reach into our array and pick out an entry that matching value in the `string` property. This is something that I didn't realize (for some reason) and was pointed out by **PuckiSilver** and **amandin** on the Datapack Hub discord server. ```vb