Skip to content

Commit

Permalink
Try fixing lock acquiring issue in extra task optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHua269 committed Aug 6, 2024
1 parent 8e876b4 commit 1299dbf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
22 changes: 4 additions & 18 deletions patches/server/0020-Try-optimizing-the-task-dispatching.patch
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,10 @@ index 8197ccb1c4e5878dbd8007b5fb514640765ec8e4..81db3c6f330729cb353b198badc86fe2
return;
}
diff --git a/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java b/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java
index ce388e0ef231d7d73f75f5778c58eb40f6402f0f..bba0d3b572cf9aa7c03816c0a74b7579b2280210 100644
index ce388e0ef231d7d73f75f5778c58eb40f6402f0f..7f8473a6db78dc652e0ccfdb7cc038126f1e61ea 100644
--- a/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java
+++ b/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java
@@ -676,13 +676,13 @@ public final class ThreadedRegionizer<R extends ThreadedRegionizer.ThreadedRegio
private static final AtomicLong REGION_ID_GENERATOR = new AtomicLong();

private static final int STATE_TRANSIENT = 0;
- private static final int STATE_READY = 1;
+ public static final int STATE_READY = 1; // Luminol - Optimize task dispatching
private static final int STATE_TICKING = 2;
private static final int STATE_DEAD = 3;
@@ -682,7 +682,7 @@ public final class ThreadedRegionizer<R extends ThreadedRegionizer.ThreadedRegio

public final long id;

Expand All @@ -51,27 +44,20 @@ index ce388e0ef231d7d73f75f5778c58eb40f6402f0f..bba0d3b572cf9aa7c03816c0a74b7579
private final Long2ReferenceOpenHashMap<ThreadedRegionSection<R, S>> sectionByKey = new Long2ReferenceOpenHashMap<>();
private final ReferenceOpenHashSet<ThreadedRegionSection<R, S>> deadSections = new ReferenceOpenHashSet<>();
diff --git a/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java b/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java
index c43b263e6502ba48a876803385f8d05c5e84ba3e..0197be1de64afbcda4897a8613e999239b90133a 100644
index c43b263e6502ba48a876803385f8d05c5e84ba3e..bfabe758e61e196fd9f4abb3ee793ef3be420c6d 100644
--- a/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java
+++ b/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java
@@ -357,6 +357,54 @@ public final class TickRegionScheduler {
@@ -357,6 +357,47 @@ public final class TickRegionScheduler {
return !this.markNotTicking() || this.cancelled.get() ? null : Boolean.valueOf(ret);
}

+ @Override
+ public boolean flushExtraTask(){
+ if (this.region != null && this.region.region.state != ThreadedRegionizer.ThreadedRegion.STATE_READY){
+ return false;
+ }
+
+ if (this.cancelled.get()) {
+ return false;
+ }
+
+ if (!this.tryMarkTicking()) {
+ if (!this.cancelled.get()) {
+ throw new IllegalStateException("Scheduled region should be acquirable");
+ }
+ return false;
+ }
+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Threaded region start tick and finished tick event


diff --git a/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java b/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java
index 0197be1de64afbcda4897a8613e999239b90133a..dfc35e9fc5c627d13a844379d782c611e3435917 100644
index bfabe758e61e196fd9f4abb3ee793ef3be420c6d..7817fad2c7aa8ae73c0720a749fe45dcfface610 100644
--- a/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java
+++ b/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java
@@ -442,7 +442,7 @@ public final class TickRegionScheduler {
@@ -435,7 +435,7 @@ public final class TickRegionScheduler {

final long scheduledStart = this.getScheduledStart();
final long scheduledEnd = scheduledStart + TIME_BETWEEN_TICKS;
Expand All @@ -17,7 +17,7 @@ index 0197be1de64afbcda4897a8613e999239b90133a..dfc35e9fc5c627d13a844379d782c611
synchronized (this) {
this.currentTickData = new TickTime(
lastTickStart, scheduledStart, tickStart, cpuStart,
@@ -477,6 +477,7 @@ public final class TickRegionScheduler {
@@ -470,6 +470,7 @@ public final class TickRegionScheduler {
);

this.addTickTime(time);
Expand Down

0 comments on commit 1299dbf

Please sign in to comment.