Attempt at even more agressive optimizations

This commit is contained in:
mcrcortex
2025-04-27 02:15:14 +10:00
parent 4a3291f4a6
commit 6d99f45412
3 changed files with 24 additions and 3 deletions

View File

@@ -46,7 +46,7 @@ public class ModelBakerySubsystem {
//There should be a method to access the frame time IIRC, if the user framecap is unlimited lock it to like 60 fps for computation
int BUDGET = 10;//TODO: make this computed based on the remaining free time in a frame (and like div by 2 to reduce overhead) (with a min of 1)
int BUDGET = 16;//TODO: make this computed based on the remaining free time in a frame (and like div by 2 to reduce overhead) (with a min of 1)
if (!this.blockIdQueue.isEmpty()) {
int[] est = new int[Math.min(this.blockIdQueue.size(), BUDGET)];
int i = 0;

View File

@@ -134,8 +134,8 @@ public class RenderService<T extends AbstractSectionRenderer<J, ?>, J extends Vi
this.sectionUpdateQueue.consume(128);
//Cap the number of consumed sections per frame to 40 + 2% of the queue size, cap of 200
int geoUpdateCap = Math.max(100, Math.min((int)(0.15*this.geometryUpdateQueue.count()), 260));
this.geometryUpdateQueue.consume(geoUpdateCap);
//int geoUpdateCap = 20;//Math.max(100, Math.min((int)(0.15*this.geometryUpdateQueue.count()), 260));
this.geometryUpdateQueue.consumeMillis(2);
if (this.nodeManager.writeChanges(this.traversal.getNodeBuffer())) {//TODO: maybe move the node buffer out of the traversal class
UploadStream.INSTANCE.commit();
}

View File

@@ -23,6 +23,9 @@ public class MessageQueue <T> {
}
public int consume(int max) {
if (this.count.get() == 0) {
return 0;
}
int i = 0;
while (i < max) {
var entry = this.queue.poll();
@@ -36,6 +39,24 @@ public class MessageQueue <T> {
return i;
}
public int consumeMillis(int millis) {
if (this.count.get() == 0) {
return 0;
}
int i = 0;
long nano = System.nanoTime();
do {
var entry = this.queue.poll();
if (entry == null) break;
i++;
this.consumer.accept(entry);
} while ((System.nanoTime()-nano) < millis*1000_000L);
if (i != 0) {
this.count.addAndGet(-i);
}
return i;
}
public final void clear(Consumer<T> cleaner) {
while (!this.queue.isEmpty()) {
cleaner.accept(this.queue.pop());