mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-29 12:09:07 +00:00
Performance improvements
This commit is contained in:
@@ -1449,4 +1449,9 @@ public interface Hunk<T> {
|
||||
default boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean contains(int x, int y, int z)
|
||||
{
|
||||
return x < getWidth() && x >= 0 && y < getHeight() && y >= 0 && z < getDepth() && z >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,17 @@ public class Mantle {
|
||||
get(x >> 5, z >> 5).getOrCreate(x & 31, z & 31).iterate(type, iterator);
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
public <T> void iterateChunk(int x, int z, Class<T> type, Consumer4<Integer, Integer, Integer, T> iterator, BurstExecutor e, MantleFlag... requiredFlags) {
|
||||
for (MantleFlag i : requiredFlags) {
|
||||
if (!hasFlag(x, z, i)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
get(x >> 5, z >> 5).getOrCreate(x & 31, z & 31).iterate(type, iterator, e);
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
public boolean hasFlag(int x, int z, MantleFlag flag) {
|
||||
return get(x >> 5, z >> 5).getOrCreate(x & 31, z & 31).isFlagged(flag);
|
||||
|
||||
@@ -23,6 +23,8 @@ import com.volmit.iris.util.function.Consumer4;
|
||||
import com.volmit.iris.util.matter.IrisMatter;
|
||||
import com.volmit.iris.util.matter.Matter;
|
||||
import com.volmit.iris.util.matter.MatterSlice;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -184,6 +186,26 @@ public class MantleChunk {
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void iterate(Class<T> type, Consumer4<Integer, Integer, Integer, T> iterator, BurstExecutor burst) {
|
||||
for (int i = 0; i < sections.length(); i++) {
|
||||
int finalI = i;
|
||||
burst.queue(() -> {
|
||||
int bs = (finalI << 4);
|
||||
Matter matter = get(finalI);
|
||||
|
||||
if (matter != null) {
|
||||
MatterSlice<T> t = matter.getSlice(type);
|
||||
|
||||
if (t != null) {
|
||||
t.iterateSync((a, b, c, f) -> iterator.accept(a, b + bs, c, f));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
burst.complete();
|
||||
}
|
||||
|
||||
public <T> void iterate(Class<T> type, Consumer4<Integer, Integer, Integer, T> iterator) {
|
||||
for (int i = 0; i < sections.length(); i++) {
|
||||
int bs = (i << 4);
|
||||
|
||||
@@ -20,6 +20,7 @@ package com.volmit.iris.util.parallel;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
@@ -28,6 +29,8 @@ import java.util.concurrent.*;
|
||||
public class BurstExecutor {
|
||||
private final ExecutorService executor;
|
||||
private final KList<CompletableFuture<Void>> futures;
|
||||
@Setter
|
||||
private boolean multicore = true;
|
||||
|
||||
public BurstExecutor(ExecutorService executor, int burstSizeEstimate) {
|
||||
this.executor = executor;
|
||||
@@ -36,6 +39,12 @@ public class BurstExecutor {
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public CompletableFuture<Void> queue(Runnable r) {
|
||||
if(!multicore)
|
||||
{
|
||||
r.run();
|
||||
return null;
|
||||
}
|
||||
|
||||
synchronized (futures) {
|
||||
CompletableFuture<Void> c = CompletableFuture.runAsync(r, executor);
|
||||
futures.add(c);
|
||||
@@ -44,6 +53,16 @@ public class BurstExecutor {
|
||||
}
|
||||
|
||||
public BurstExecutor queue(List<Runnable> r) {
|
||||
if(!multicore)
|
||||
{
|
||||
for(Runnable i : r)
|
||||
{
|
||||
i.run();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
synchronized (futures) {
|
||||
for (Runnable i : new KList<>(r)) {
|
||||
CompletableFuture<Void> c = CompletableFuture.runAsync(i, executor);
|
||||
@@ -55,6 +74,16 @@ public class BurstExecutor {
|
||||
}
|
||||
|
||||
public BurstExecutor queue(Runnable[] r) {
|
||||
if(!multicore)
|
||||
{
|
||||
for(Runnable i : r)
|
||||
{
|
||||
i.run();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
synchronized (futures) {
|
||||
for (Runnable i : r) {
|
||||
CompletableFuture<Void> c = CompletableFuture.runAsync(i, executor);
|
||||
@@ -66,6 +95,11 @@ public class BurstExecutor {
|
||||
}
|
||||
|
||||
public void complete() {
|
||||
if(!multicore)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (futures) {
|
||||
if (futures.isEmpty()) {
|
||||
return;
|
||||
@@ -81,6 +115,11 @@ public class BurstExecutor {
|
||||
}
|
||||
|
||||
public boolean complete(long maxDur) {
|
||||
if(!multicore)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
synchronized (futures) {
|
||||
if (futures.isEmpty()) {
|
||||
return true;
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.volmit.iris.util.parallel;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.service.PreservationSVC;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.io.InstanceState;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
@@ -111,6 +112,12 @@ public class MultiBurst {
|
||||
}
|
||||
}
|
||||
|
||||
public void sync(KList<Runnable> r) {
|
||||
for (Runnable i : r) {
|
||||
i.run();
|
||||
}
|
||||
}
|
||||
|
||||
public BurstExecutor burst(int estimate) {
|
||||
return new BurstExecutor(getService(), estimate);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user