|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Preva1l <prod.preva1l@gmail.com> |
| 3 | +Date: Thu, 30 Oct 2025 21:52:52 -0700 |
| 4 | +Subject: [PATCH] Further reduce impact of tick time calculations, |
| 5 | + PaperPR#13256 |
| 6 | + |
| 7 | + |
| 8 | +diff --git a/src/main/java/ca/spottedleaf/moonrise/common/time/TickData.java b/src/main/java/ca/spottedleaf/moonrise/common/time/TickData.java |
| 9 | +index 7e4fec66f1f7e9daabd015cde689e67736d6a54a..b562acd4d87a75e66f5256dd85faf48eff26f552 100644 |
| 10 | +--- a/src/main/java/ca/spottedleaf/moonrise/common/time/TickData.java |
| 11 | ++++ b/src/main/java/ca/spottedleaf/moonrise/common/time/TickData.java |
| 12 | +@@ -292,78 +292,51 @@ public final class TickData { |
| 13 | + // So, we will "compact" the data by merging any inbetween tick times |
| 14 | + // the next tick. |
| 15 | + // If there is no "next tick", then we will create one. |
| 16 | +- final List<TickInformation> collapsedData = new ArrayList<>(); |
| 17 | +- for (int i = 0, len = allData.size(); i < len; ++i) { |
| 18 | +- final List<TickTime> toCollapse = new ArrayList<>(); |
| 19 | +- TickTime lastTick = null; |
| 20 | +- for (;i < len; ++i) { |
| 21 | +- final TickTime time = allData.get(i); |
| 22 | +- if (!time.isTickExecution()) { |
| 23 | +- toCollapse.add(time); |
| 24 | +- continue; |
| 25 | +- } |
| 26 | +- lastTick = time; |
| 27 | +- break; |
| 28 | +- } |
| 29 | ++ final int len = allData.size(); |
| 30 | ++ final List<TickInformation> collapsedData = new ArrayList<>(len); |
| 31 | ++ |
| 32 | ++ long totalTickTime = 0L; |
| 33 | ++ long totalCpuTime = 0L; |
| 34 | ++ TickTime lastActualTick = null; |
| 35 | ++ |
| 36 | ++ for (final TickTime time : allData) { |
| 37 | ++ if (!time.isTickExecution()) { |
| 38 | ++ totalTickTime += time.tickLength(); |
| 39 | ++ totalCpuTime += time.supportCPUTime() ? time.tickCpuTime() : 0L; |
| 40 | ++ } else { |
| 41 | ++ final long tickCpu = time.supportCPUTime() ? time.tickCpuTime() : 0L; |
| 42 | + |
| 43 | +- if (toCollapse.isEmpty()) { |
| 44 | +- // nothing to collapse |
| 45 | +- final TickTime last = allData.get(i); |
| 46 | + collapsedData.add( |
| 47 | + new TickInformation( |
| 48 | +- last.differenceFromLastTick(tickInterval), |
| 49 | +- last.tickLength(), |
| 50 | +- last.supportCPUTime() ? last.tickCpuTime() : 0L |
| 51 | ++ time.differenceFromLastTick(tickInterval), |
| 52 | ++ time.tickLength() + totalTickTime, |
| 53 | ++ tickCpu + totalCpuTime |
| 54 | + ) |
| 55 | + ); |
| 56 | ++ |
| 57 | ++ totalTickTime = 0L; |
| 58 | ++ totalCpuTime = 0L; |
| 59 | ++ lastActualTick = time; |
| 60 | ++ } |
| 61 | ++ } |
| 62 | ++ |
| 63 | ++ if (totalTickTime > 0 && createFakeTick) { |
| 64 | ++ final long differenceBetweenTicks; |
| 65 | ++ if (lastActualTick != null) { |
| 66 | ++ differenceBetweenTicks = lastActualTick.tickStart(); |
| 67 | + } else { |
| 68 | +- long totalTickTime = 0L; |
| 69 | +- long totalCpuTime = 0L; |
| 70 | +- for (int k = 0, len2 = toCollapse.size(); k < len2; ++k) { |
| 71 | +- final TickTime time = toCollapse.get(k); |
| 72 | +- totalTickTime += time.tickLength(); |
| 73 | +- totalCpuTime += time.supportCPUTime() ? time.tickCpuTime() : 0L; |
| 74 | +- } |
| 75 | +- if (i < len) { |
| 76 | +- // we know there is a tick to collapse into |
| 77 | +- final TickTime last = allData.get(i); |
| 78 | +- collapsedData.add( |
| 79 | +- new TickInformation( |
| 80 | +- last.differenceFromLastTick(tickInterval), |
| 81 | +- last.tickLength() + totalTickTime, |
| 82 | +- (last.supportCPUTime() ? last.tickCpuTime() : 0L) + totalCpuTime |
| 83 | +- ) |
| 84 | +- ); |
| 85 | +- } else if (createFakeTick) { |
| 86 | +- // we do not have a tick to collapse into, so we must make one up |
| 87 | +- // we will assume that the tick is "starting now" and ongoing |
| 88 | +- |
| 89 | +- // compute difference between imaginary tick and last tick |
| 90 | +- final long differenceBetweenTicks; |
| 91 | +- if (lastTick != null) { |
| 92 | +- // we have a last tick, use it |
| 93 | +- differenceBetweenTicks = lastTick.tickStart(); |
| 94 | +- } else { |
| 95 | +- // we don't have a last tick, so we must make one up that makes sense |
| 96 | +- // if the current interval exceeds the max tick time, then use it |
| 97 | +- |
| 98 | +- // Otherwise use the interval length. |
| 99 | +- // This is how differenceFromLastTick() works on TickTime when there is no previous interval. |
| 100 | +- differenceBetweenTicks = Math.max( |
| 101 | +- tickInterval, totalTickTime |
| 102 | +- ); |
| 103 | +- } |
| 104 | +- |
| 105 | +- collapsedData.add( |
| 106 | +- new TickInformation( |
| 107 | +- differenceBetweenTicks, |
| 108 | +- totalTickTime, |
| 109 | +- totalCpuTime |
| 110 | +- ) |
| 111 | +- ); |
| 112 | +- } |
| 113 | ++ differenceBetweenTicks = Math.max(tickInterval, totalTickTime); |
| 114 | + } |
| 115 | ++ |
| 116 | ++ collapsedData.add( |
| 117 | ++ new TickInformation( |
| 118 | ++ differenceBetweenTicks, |
| 119 | ++ totalTickTime, |
| 120 | ++ totalCpuTime |
| 121 | ++ ) |
| 122 | ++ ); |
| 123 | + } |
| 124 | ++ |
| 125 | + return collapsedData; |
| 126 | + } |
| 127 | + |
0 commit comments