Performance
PerformanceManager reports callback timing for your plugin and memory figures for the runtime.
package dev.example;
import dev.zernyth.api.performance.PerformanceOptions;
import dev.zernyth.api.plugin.JavaPlugin;
import java.time.Duration;
public final class ProfilingPlugin extends JavaPlugin {
@Override
public void onEnable() {
var performance = getServer().getPerformanceManager();
performance.configure(new PerformanceOptions(true, Duration.ofMillis(5), 100));
getServer().getScheduler().runTaskTimer(() -> {
for (var callback : performance.getPluginSnapshot().callbacks()) {
getLogger().info(callback.kind() + ": " + callback.calls() + " calls, " + callback.slowCalls() + " slow");
}
getLogger().info("Heap used: " + performance.getRuntimeMemorySnapshot().heapUsed());
}, 200, 1200);
}
}Guidelines
- Never block the server thread. Use AsyncRuntime for I/O and heavy work.
- Avoid repeated
Dimensionchunk checks in hot code: the check walks the native list of loaded chunks. - Do not change configuration from code that runs every tick.
- Each scheduler pulse stops admitting server callbacks after a 2 ms budget. A single callback can exceed it.
getDiagnostics() on JavaPlugin returns load, enable and disable timings.