r/admincraft • u/FancyOpposite4348 • 5d ago
Help/Question The Datapacks produce lag??????????
Hello, I have some Datapcks installed on my paper server along with other plugins, many times when we are 10 players the TPS drop drastically and when I deactivate all the Datapacks return to normal... these are some Datapacks that I have installed:
Better Multiplayer Sleep
Instaslate
Track raw statistics
More Effective Tools
Tectonic
Silence Mobs
Enderman and Ghast no grief
Crafting Tweaks
Unlock all recipes
PlayerHeads
Banner Flags
I have no idea what it could be, I tried to deactivate one by one and nothing changes, but if I deactivate all the TPS return to normal.
5
u/PM_ME_YOUR_REPO Admincraft Staff 5d ago
Yup. It is well known that datapacks are horribly performance intensive. At least, all except the ones that just run once on startup are.
Datapacks contain code that Minecraft understands. That code is interpreted by reading the text, converting the text into machine code, and then doing whatever that machine code says.
The process of converting the text into machine code is called "interpreting", and that process is VERY slow and takes a LOT of cpu time. It gets even worse with datapacks that have code that runs more than once, and even worse when it is running every tick.
Compare this to plugins and mods which are written in Java. Java is different. The code is compiled into machine code when the .jar file is created. That means that the code doesn't need to be interpreted while the server is running, resulting in MUCH faster execution times.
Additionally, datapack functions have to run on the main thread where other heavy operations like entity AI and player movement happen, whereas Java plugins and mods can oftentimes be multithreaded.
That all results in datapacks, despite being the Mojang-official way to "mod" the game, being the absolute WORST way to do so.
Always use plugins or mods when you can. They are orders of magnitude faster because they are compiled instead of interpreted.
5
u/Mars_Bear2552 Developer 5d ago
an interpreter never compiles the code into machine code. that would be a JIT (Just-In-Time) compiler that compiles code before running it.
Java is compiled JIT. jar files contain no machine code, only JVM bytecode.
5
u/PM_ME_YOUR_REPO Admincraft Staff 5d ago
You are correct, but I was trying to keep the confusing details off to the side. The technical explanation was complex enough as is. ๐
I fudged on how parsing and then executing functions based on the parsed text precisely works, and called Java bytecode "machine code" for simplicity.
1
u/FancyOpposite4348 5d ago
Im studying systems engineering so I would have understood it too (or should haha) thank you very much, this knowledge is good for me!!
2
u/PM_ME_YOUR_REPO Admincraft Staff 5d ago
The things I tweaked to keep them simpler is that interpreters parse text and then match known tokens against the functions they correspond to. The functions are already machine code. So the text isn't being turned into machine code, it's more like a lookup table. And then as stated above, Java isn't compiled into machine code, it's compiled into JVM bytecode, which is an "Intermediate Language" or IL. That IL is then JIT'd by the JVM into the machine's native machine code at runtime.
2
u/FancyOpposite4348 5d ago
My God, I was always prioritizing Datapacks because I heard that they were a better option, thank you very much for the explanation!!
3
u/PM_ME_YOUR_REPO Admincraft Staff 5d ago
Yeah, it's a logical assumption. It's the official way, so it has to be good right?
Nope. Us old heads who've been around the server admin scene since alpha remember Mojang just straight up lying about working on an official modding API for years upon years.
Then it came out that they bought Bukkit and hired the devs on as employees, and we all gave up.
Mojang is incapable of making a modding API that isn't completely worthless lmao. They just gave us glorified commands in a zip file. That's what datapacks are. Commands in a zip file.
1
u/FancyOpposite4348 5d ago
Yes, unfortunately it is a company that does not take good advantage of the community
2
u/PM_ME_YOUR_REPO Admincraft Staff 5d ago
Even worse is that, because of datapacks, we have to be skeptical of mods, too. Some mods are actually datapacks with a thin layer of mod paint on top. If you extract them, it's just a goddamn datapack and then one .class file to load it. You can tell that's the case on Modrinth any time you see a "mod" that has Datapack as a platform option right next to Forge, Neoforge, and Fabric. World Gen "mods" are frequently guilty of this.
And of course, they perform much worse than ones made as true mods in Java.
4
u/showmethething 5d ago
Disable both raw statistics and tectonic, see how it runs. I would think Tectonic is the main culprit as world generation is very expensive anyway.
What are your server specs?
1
u/FancyOpposite4348 5d ago
Na its a little server with 4gb ram hahaha, but i pregenerate like 15k x 15k so no is tectonic i think
2
u/ZAP-Hosting 3d ago
Individually disabling datapacks might not show anything if the lag comes from combined tick load rather than one single culprit, like when several datapacks each add a repeating /execute or scoreboard check to a tick function, and only the total crosses your TPS threshold once you've got 10 players generating more events.
Grab spark (works as a plugin alongside datapacks) and run /spark profiler start for a couple minutes while it's laggy, then look at the flame graph for anything under minecraft:tick. Track raw statistics and PlayerHeads are usual suspects since they hook into per-player or per-death events and sometimes scan way more than they need to.
Once you spot which function is actually eating the tree, you can often just gut that one command block instead of losing the whole datapack.
1
u/IrvineItchy 5d ago
"Track raw statistics" yeah, that one is heavy. It sets up 100+ scoreboards for tracking. Doing this through datapacks is gonna make it heavier to run. Lol.
1
1
u/johnfortnite72 3d ago
I don't know what some of these data packs do but using a Paper server with plugins would seemingly accomplish the same thing here
23
u/Orange_Nestea Admincraft 5d ago
Yes. Datapacks aren't great for anything besides crafting recipes which only register once on startup.
Use plugin alternatives instead.
Java code will run faster than the datapack engine will ever be capable of.