#Unoptimised
1 messages · Page 1 of 1 (latest)
wdym?
A command exists in the game called /script profilerof which gives you an overview which native calls are being overused, causing script tick lag.
this?

In-game, you'll want to run that command within a defined time for best practice. Start the profile using /script profiler start and play through the motions of a player loading and unloading a plot.
Then, run /script profiler stop and make note of the output. The output should contain a file path that can be put into the extension basically.
W
unfortunatley
nothing bad found
I find that hard to believe with a script tick jolt that high.
What function was the highest?

how much time is taken for the function to resolve
uncollapsing them reveals the line it was called on
is 57ms bad?
how long were you running it, 30 seconds?
either way, 57ms is not bad at all
world.getPlayers is a bit more concerning
this is it
that prob explains the tick rate being elevated outside of the spike
not sure where the spike is coming from without seeing the full codebase
how often does that spike occur?
and are we sure it's the plot system
i mean
the spike is happening when i leave
I see, structures are still fairly performance draining but interesting that it's being shown as a tick spike.
jesus
I guess I underestimated that. My guess it's when a structure is being placed.
Eh, pretty average for an addon tbh
You can improve it by simply adding caching measures.
alright thanks
ill try optimise this ig
idk how
Not sure if you can improve structure performance at all.
yeah especially saving
As for everything else like native calls for players, you can do something super simple like saving joined players to an external playerList variable and then removing them when they leave. This way getPlayers is only ever called like 20 times in a session all-together.
well i need the interval to actually eject playerss from plots they are not supposed to be in
Just use the playerList variable I mean instead of directly calling getPlayers
Let me find an example
import { world, Player, system } from "@minecraft/server";
let playerList = [];
/**
* @returns {Player[]}
*/
export function getPlayerList() {
return playerList;
}
world.afterEvents.worldLoad.subscribe(() => {
playerList = world.getAllPlayers();
});
world.afterEvents.playerSpawn.subscribe(ev => {
if (!ev.initialSpawn) return;
playerList = world.getAllPlayers()
});
world.afterEvents.playerLeave.subscribe(ev => {
playerList = world.getAllPlayers();
})```
@past pond this saves the player list only on join and leave then you can call that function to return the cached objects.
It’s considered faster because directly calling the function every tick just takes more time to resolve than if it’s stored in memory.