From 6d99f45412c5bba35d39390017c1477e72f14482 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Sun, 27 Apr 2025 02:15:14 +1000 Subject: [PATCH] Attempt at even more agressive optimizations --- .../core/model/ModelBakerySubsystem.java | 2 +- .../client/core/rendering/RenderService.java | 4 ++-- .../cortex/voxy/common/util/MessageQueue.java | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/core/model/ModelBakerySubsystem.java b/src/main/java/me/cortex/voxy/client/core/model/ModelBakerySubsystem.java index 9bada669..c3d59af0 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/ModelBakerySubsystem.java +++ b/src/main/java/me/cortex/voxy/client/core/model/ModelBakerySubsystem.java @@ -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; diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java b/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java index 56d616c0..b3c0f728 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java @@ -134,8 +134,8 @@ public class RenderService, 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(); } diff --git a/src/main/java/me/cortex/voxy/common/util/MessageQueue.java b/src/main/java/me/cortex/voxy/common/util/MessageQueue.java index a2b18bee..8d2a0d47 100644 --- a/src/main/java/me/cortex/voxy/common/util/MessageQueue.java +++ b/src/main/java/me/cortex/voxy/common/util/MessageQueue.java @@ -23,6 +23,9 @@ public class MessageQueue { } 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 { 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 cleaner) { while (!this.queue.isEmpty()) { cleaner.accept(this.queue.pop());