From c095f7da28fcf875e6aac83407d0cf0d5f048190 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Thu, 20 Aug 2020 21:21:35 -0400 Subject: [PATCH] Small Optimization --- .../api/energy/tick/EnergyTicker.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/thebrokenrail/energonrelics/api/energy/tick/EnergyTicker.java b/src/main/java/com/thebrokenrail/energonrelics/api/energy/tick/EnergyTicker.java index af38106..3690389 100644 --- a/src/main/java/com/thebrokenrail/energonrelics/api/energy/tick/EnergyTicker.java +++ b/src/main/java/com/thebrokenrail/energonrelics/api/energy/tick/EnergyTicker.java @@ -47,6 +47,8 @@ public class EnergyTicker { NetworkComponent.getInstance((ServerWorld) world).clearCache(); + world.getProfiler().push("startTick"); + List started = new ArrayList<>(); List temp = new ArrayList<>(scheduled); @@ -54,7 +56,7 @@ public class EnergyTicker { while (!temp.isEmpty()) { for (EnergyTickable tickable : temp) { if (!started.contains(tickable)) { - world.getProfiler().push(() -> tickable.getID() + " startTick"); + world.getProfiler().push(tickable::getID); temp2.addAll(tickable.startTick()); started.add(tickable); @@ -62,8 +64,10 @@ public class EnergyTicker { world.getProfiler().pop(); } } - temp.clear(); - temp.addAll(temp2); + + List temp3 = temp; + temp = temp2; + temp2 = temp3; temp2.clear(); } @@ -73,8 +77,12 @@ public class EnergyTicker { Collections.shuffle(started, world.random); world.getProfiler().pop(); + world.getProfiler().pop(); + + world.getProfiler().push("logicTick"); + for (EnergyTickable tickable : started) { - world.getProfiler().push(() -> tickable.getID() + " logicTick"); + world.getProfiler().push(tickable::getID); tickable.logicTick(); @@ -82,6 +90,8 @@ public class EnergyTicker { } world.getProfiler().pop(); + + world.getProfiler().pop(); } scheduled.clear();