Merge pull request #10 from ludovic111/wakeable-terrain-idle

Wake idle distant-terrain queues when new work arrives
This commit is contained in:
Ludovic Marie
2026-10-03 23:45:54 +02:00
committed by GitHub
17 changed files with 388 additions and 7 deletions
+3
View File
@@ -50,6 +50,8 @@ jobs:
run: python -c "from tools.build_mod import benchmark_workers; benchmark_workers()"
- name: Measure isolated debounce queue polling
run: python -c "from tools.build_mod import benchmark_debounce; benchmark_debounce()"
- name: Measure wakeable idle queue latency
run: python -c "from tools.build_mod import benchmark_idle; benchmark_idle()"
- name: Measure object allocations with compact headers off and on
run: python -c "from tools.build_mod import benchmark_headers; benchmark_headers()"
- name: Test pack integrity and comparisons
@@ -63,4 +65,5 @@ jobs:
dist/horizon-lab-*.jar
dist/worker-pacing-benchmark.txt
dist/debounce-queue-benchmark.txt
dist/idle-queue-benchmark.txt
dist/object-header-benchmark.txt
+5 -1
View File
@@ -6,7 +6,7 @@ Client-first performance research for Minecraft Java **26.3**, preserving vanill
## Play on your Mac
Download **horizon-mac-starter-0.8.0.zip** from [Releases](https://github.com/ludovic111/minecraft-optimization-lab/releases), extract it and open `Mac-Start.command`. It verifies and installs official universal Prism Launcher in `~/Applications` if needed, then opens the balanced pack import. Sign into Microsoft **inside Prism yourself**. This project needs no credentials.
Download **horizon-mac-starter-0.9.0.zip** from [Releases](https://github.com/ludovic111/minecraft-optimization-lab/releases), extract it and open `Mac-Start.command`. It verifies and installs official universal Prism Launcher in `~/Applications` if needed, then opens the balanced pack import. Sign into Microsoft **inside Prism yourself**. This project needs no credentials.
Use native **Java 25 ARM64**, maximum heap **6144 MiB**, minimum **512 MiB** on your 16 GB M2 Pro. Prism can download Java automatically. Start at 1280×800 or 1920×1200; full Retina resolution is a larger GPU workload. [START-HERE.txt](packs/START-HERE.txt) has details. The same `.mrpack` files import into Prism on Windows and Linux.
@@ -30,6 +30,10 @@ Distant LOD is simplified terrain. Nearby blocks retain full detail. Initial gen
The optional `queue-wait` pack yields during pending distant-terrain debounce retries; `adaptive-queue` combines it with the existing controllers. [Queue experiment and measurement limits](docs/debounce-queue.md).
Version 0.9 also makes the queue's idle wait wakeable for incoming work, preserving
its debounce rules and bounded cache-maintenance cadence. It remains part of the
optional queue profiles, with separate wake-latency measurements.
Version 0.8 fixes a fresh-instance graphics preset that could override the selected
render distance. It also records actual GC/header settings and supports an optional
[compact object headers experiment](docs/compact-headers.md) for Java 25; packs
@@ -0,0 +1,42 @@
Java openjdk 25.0.4.1 2026-08-18 LTS
Platform Darwin 25.6.0 arm64; logical CPUs 3
mode=upstream trial=0 incoming_after_idle_ms=26.655 publication_to_pop_ms=27.930
mode=wakeable trial=0 incoming_after_idle_ms=23.086 publication_to_pop_ms=0.098
mode=upstream trial=1 incoming_after_idle_ms=25.029 publication_to_pop_ms=94.707
mode=wakeable trial=1 incoming_after_idle_ms=19.340 publication_to_pop_ms=16.096
mode=upstream trial=2 incoming_after_idle_ms=16.530 publication_to_pop_ms=98.696
mode=wakeable trial=2 incoming_after_idle_ms=12.085 publication_to_pop_ms=0.080
mode=upstream trial=3 incoming_after_idle_ms=20.350 publication_to_pop_ms=50.086
mode=wakeable trial=3 incoming_after_idle_ms=15.681 publication_to_pop_ms=0.051
mode=upstream trial=4 incoming_after_idle_ms=26.474 publication_to_pop_ms=90.380
mode=wakeable trial=4 incoming_after_idle_ms=21.794 publication_to_pop_ms=0.054
mode=upstream trial=5 incoming_after_idle_ms=20.069 publication_to_pop_ms=91.508
mode=wakeable trial=5 incoming_after_idle_ms=14.527 publication_to_pop_ms=0.069
mode=upstream trial=6 incoming_after_idle_ms=25.051 publication_to_pop_ms=58.889
mode=wakeable trial=6 incoming_after_idle_ms=20.193 publication_to_pop_ms=0.081
mode=upstream trial=7 incoming_after_idle_ms=12.084 publication_to_pop_ms=41.323
mode=wakeable trial=7 incoming_after_idle_ms=5.867 publication_to_pop_ms=0.057
mode=upstream trial=8 incoming_after_idle_ms=19.023 publication_to_pop_ms=99.615
mode=wakeable trial=8 incoming_after_idle_ms=18.833 publication_to_pop_ms=0.063
mode=upstream trial=9 incoming_after_idle_ms=13.648 publication_to_pop_ms=103.446
mode=wakeable trial=9 incoming_after_idle_ms=28.375 publication_to_pop_ms=0.056
mode=upstream trial=10 incoming_after_idle_ms=17.449 publication_to_pop_ms=98.829
mode=wakeable trial=10 incoming_after_idle_ms=24.812 publication_to_pop_ms=0.062
mode=upstream trial=11 incoming_after_idle_ms=26.751 publication_to_pop_ms=88.715
mode=wakeable trial=11 incoming_after_idle_ms=28.154 publication_to_pop_ms=0.067
mode=upstream trial=12 incoming_after_idle_ms=20.596 publication_to_pop_ms=73.247
mode=wakeable trial=12 incoming_after_idle_ms=16.397 publication_to_pop_ms=0.080
mode=upstream trial=13 incoming_after_idle_ms=19.685 publication_to_pop_ms=53.674
mode=wakeable trial=13 incoming_after_idle_ms=21.934 publication_to_pop_ms=0.050
mode=upstream trial=14 incoming_after_idle_ms=16.937 publication_to_pop_ms=37.755
mode=wakeable trial=14 incoming_after_idle_ms=18.296 publication_to_pop_ms=0.074
mode=upstream trial=15 incoming_after_idle_ms=17.572 publication_to_pop_ms=68.115
mode=wakeable trial=15 incoming_after_idle_ms=13.516 publication_to_pop_ms=0.072
mode=upstream trial=16 incoming_after_idle_ms=24.639 publication_to_pop_ms=100.433
mode=wakeable trial=16 incoming_after_idle_ms=22.918 publication_to_pop_ms=0.103
mode=upstream trial=17 incoming_after_idle_ms=30.593 publication_to_pop_ms=79.830
mode=wakeable trial=17 incoming_after_idle_ms=25.080 publication_to_pop_ms=0.053
mode=upstream trial=18 incoming_after_idle_ms=15.889 publication_to_pop_ms=108.892
mode=wakeable trial=18 incoming_after_idle_ms=27.297 publication_to_pop_ms=0.034
mode=upstream trial=19 incoming_after_idle_ms=10.808 publication_to_pop_ms=59.234
mode=wakeable trial=19 incoming_after_idle_ms=16.349 publication_to_pop_ms=0.083
@@ -0,0 +1,42 @@
Java openjdk 25.0.4.1 2026-08-18 LTS
Platform Linux 6.17.0-1022-azure x86_64; logical CPUs 4
mode=upstream trial=0 incoming_after_idle_ms=5.089 publication_to_pop_ms=45.143
mode=wakeable trial=0 incoming_after_idle_ms=5.100 publication_to_pop_ms=0.073
mode=upstream trial=1 incoming_after_idle_ms=5.125 publication_to_pop_ms=45.051
mode=wakeable trial=1 incoming_after_idle_ms=5.097 publication_to_pop_ms=0.055
mode=upstream trial=2 incoming_after_idle_ms=5.098 publication_to_pop_ms=45.135
mode=wakeable trial=2 incoming_after_idle_ms=5.088 publication_to_pop_ms=0.042
mode=upstream trial=3 incoming_after_idle_ms=5.091 publication_to_pop_ms=45.084
mode=wakeable trial=3 incoming_after_idle_ms=5.149 publication_to_pop_ms=0.049
mode=upstream trial=4 incoming_after_idle_ms=5.103 publication_to_pop_ms=45.060
mode=wakeable trial=4 incoming_after_idle_ms=5.141 publication_to_pop_ms=0.064
mode=upstream trial=5 incoming_after_idle_ms=5.127 publication_to_pop_ms=45.047
mode=wakeable trial=5 incoming_after_idle_ms=5.137 publication_to_pop_ms=0.053
mode=upstream trial=6 incoming_after_idle_ms=5.129 publication_to_pop_ms=45.177
mode=wakeable trial=6 incoming_after_idle_ms=5.134 publication_to_pop_ms=0.068
mode=upstream trial=7 incoming_after_idle_ms=5.107 publication_to_pop_ms=45.059
mode=wakeable trial=7 incoming_after_idle_ms=5.137 publication_to_pop_ms=0.061
mode=upstream trial=8 incoming_after_idle_ms=5.168 publication_to_pop_ms=45.005
mode=wakeable trial=8 incoming_after_idle_ms=5.134 publication_to_pop_ms=0.060
mode=upstream trial=9 incoming_after_idle_ms=5.105 publication_to_pop_ms=45.077
mode=wakeable trial=9 incoming_after_idle_ms=5.148 publication_to_pop_ms=0.070
mode=upstream trial=10 incoming_after_idle_ms=5.092 publication_to_pop_ms=45.197
mode=wakeable trial=10 incoming_after_idle_ms=5.136 publication_to_pop_ms=0.055
mode=upstream trial=11 incoming_after_idle_ms=5.113 publication_to_pop_ms=45.045
mode=wakeable trial=11 incoming_after_idle_ms=5.122 publication_to_pop_ms=0.044
mode=upstream trial=12 incoming_after_idle_ms=5.095 publication_to_pop_ms=45.070
mode=wakeable trial=12 incoming_after_idle_ms=5.147 publication_to_pop_ms=0.052
mode=upstream trial=13 incoming_after_idle_ms=5.118 publication_to_pop_ms=45.048
mode=wakeable trial=13 incoming_after_idle_ms=5.168 publication_to_pop_ms=0.047
mode=upstream trial=14 incoming_after_idle_ms=5.133 publication_to_pop_ms=45.129
mode=wakeable trial=14 incoming_after_idle_ms=5.155 publication_to_pop_ms=0.047
mode=upstream trial=15 incoming_after_idle_ms=5.098 publication_to_pop_ms=45.031
mode=wakeable trial=15 incoming_after_idle_ms=5.167 publication_to_pop_ms=0.044
mode=upstream trial=16 incoming_after_idle_ms=5.129 publication_to_pop_ms=45.051
mode=wakeable trial=16 incoming_after_idle_ms=5.135 publication_to_pop_ms=0.073
mode=upstream trial=17 incoming_after_idle_ms=5.148 publication_to_pop_ms=45.034
mode=wakeable trial=17 incoming_after_idle_ms=5.148 publication_to_pop_ms=0.044
mode=upstream trial=18 incoming_after_idle_ms=5.181 publication_to_pop_ms=45.103
mode=wakeable trial=18 incoming_after_idle_ms=5.127 publication_to_pop_ms=0.046
mode=upstream trial=19 incoming_after_idle_ms=5.094 publication_to_pop_ms=45.075
mode=wakeable trial=19 incoming_after_idle_ms=5.148 publication_to_pop_ms=0.051
@@ -0,0 +1,42 @@
Java openjdk 25.0.4.1 2026-08-18 LTS
Platform Windows 2025Server AMD64; logical CPUs 4
mode=upstream trial=0 incoming_after_idle_ms=5.487 publication_to_pop_ms=45.519
mode=wakeable trial=0 incoming_after_idle_ms=5.377 publication_to_pop_ms=0.127
mode=upstream trial=1 incoming_after_idle_ms=6.059 publication_to_pop_ms=44.593
mode=wakeable trial=1 incoming_after_idle_ms=5.539 publication_to_pop_ms=0.094
mode=upstream trial=2 incoming_after_idle_ms=5.096 publication_to_pop_ms=45.005
mode=wakeable trial=2 incoming_after_idle_ms=5.624 publication_to_pop_ms=0.079
mode=upstream trial=3 incoming_after_idle_ms=5.649 publication_to_pop_ms=44.691
mode=wakeable trial=3 incoming_after_idle_ms=4.731 publication_to_pop_ms=0.077
mode=upstream trial=4 incoming_after_idle_ms=5.312 publication_to_pop_ms=45.488
mode=wakeable trial=4 incoming_after_idle_ms=5.156 publication_to_pop_ms=0.108
mode=upstream trial=5 incoming_after_idle_ms=5.190 publication_to_pop_ms=45.580
mode=wakeable trial=5 incoming_after_idle_ms=5.457 publication_to_pop_ms=0.077
mode=upstream trial=6 incoming_after_idle_ms=5.141 publication_to_pop_ms=45.619
mode=wakeable trial=6 incoming_after_idle_ms=5.592 publication_to_pop_ms=0.074
mode=upstream trial=7 incoming_after_idle_ms=5.823 publication_to_pop_ms=44.487
mode=wakeable trial=7 incoming_after_idle_ms=5.355 publication_to_pop_ms=0.066
mode=upstream trial=8 incoming_after_idle_ms=5.675 publication_to_pop_ms=45.050
mode=wakeable trial=8 incoming_after_idle_ms=5.252 publication_to_pop_ms=0.075
mode=upstream trial=9 incoming_after_idle_ms=5.921 publication_to_pop_ms=44.505
mode=wakeable trial=9 incoming_after_idle_ms=6.002 publication_to_pop_ms=0.072
mode=upstream trial=10 incoming_after_idle_ms=5.797 publication_to_pop_ms=44.517
mode=wakeable trial=10 incoming_after_idle_ms=5.103 publication_to_pop_ms=0.070
mode=upstream trial=11 incoming_after_idle_ms=5.115 publication_to_pop_ms=45.066
mode=wakeable trial=11 incoming_after_idle_ms=5.638 publication_to_pop_ms=0.071
mode=upstream trial=12 incoming_after_idle_ms=5.239 publication_to_pop_ms=45.538
mode=wakeable trial=12 incoming_after_idle_ms=5.666 publication_to_pop_ms=0.083
mode=upstream trial=13 incoming_after_idle_ms=5.136 publication_to_pop_ms=45.251
mode=wakeable trial=13 incoming_after_idle_ms=4.163 publication_to_pop_ms=0.073
mode=upstream trial=14 incoming_after_idle_ms=5.256 publication_to_pop_ms=46.048
mode=wakeable trial=14 incoming_after_idle_ms=5.545 publication_to_pop_ms=0.074
mode=upstream trial=15 incoming_after_idle_ms=4.239 publication_to_pop_ms=47.028
mode=wakeable trial=15 incoming_after_idle_ms=5.292 publication_to_pop_ms=0.053
mode=upstream trial=16 incoming_after_idle_ms=5.959 publication_to_pop_ms=45.046
mode=wakeable trial=16 incoming_after_idle_ms=5.230 publication_to_pop_ms=0.182
mode=upstream trial=17 incoming_after_idle_ms=5.153 publication_to_pop_ms=45.005
mode=wakeable trial=17 incoming_after_idle_ms=5.220 publication_to_pop_ms=0.066
mode=upstream trial=18 incoming_after_idle_ms=5.358 publication_to_pop_ms=46.008
mode=wakeable trial=18 incoming_after_idle_ms=5.156 publication_to_pop_ms=0.062
mode=upstream trial=19 incoming_after_idle_ms=4.370 publication_to_pop_ms=47.015
mode=wakeable trial=19 incoming_after_idle_ms=5.162 publication_to_pop_ms=0.073
+40 -4
View File
@@ -13,8 +13,10 @@ settings, mods and worker budgets. Its original hook performs the existing
debounce reinsertion, then requests a wait of up to 1 ms, bounded by the remaining
deadline, if no preprocessing work is pending. It only waits on the queue worker,
never a caller such as the render thread. Incoming queued work unparks a debounce
wait; the original empty-queue sleep remains unchanged. OS scheduling determines
when the worker resumes.
wait. Starting with 0.9, incoming work can also wake an empty queue's idle wait,
which previously slept for 50 ms. The idle park ends by the next 50 ms cache
maintenance deadline; early wakeups do not trigger maintenance more often than
that cadence. OS scheduling determines when the worker resumes.
The same update object, priority queue, debounce timestamp, overload policy,
executor dispatch and normal simulation remain in use. Executor-unavailable and
rejected-dispatch retries are outside this hook.
@@ -27,12 +29,46 @@ Set `enabled=false` in `config/horizon-queue-wait.properties` and restart to
disable the queue hook. It is disabled by default and requires exact DH 3.3.4.
Requested waits are not hard latency bounds: operating-system timers can
overshoot, and arrival/worker scheduling affect responsiveness. Parking leaves
the interruption flag intact, so the existing shutdown loop still handles it.
overshoot, and arrival/worker scheduling affect responsiveness. Debounce parking
leaves the interruption flag intact, so the existing shutdown loop handles it.
The wakeable idle wait throws with a cleared interrupt flag, as `Thread.sleep`
did; the original catch restores the flag and exits on the next loop check.
New arrival wakeups reduce the chance of delaying useful preprocessing, but
real terrain completion, block-change visibility and platform behavior need
evaluation alongside CPU, allocations and frame pacing.
## Idle wakeup experiment in 0.9
After building, run
`python -c "from tools.build_mod import benchmark_idle; benchmark_idle()"`.
An actual publisher queue starts empty; synthetic incoming work is published
about 5 ms into an idle interval. Separate upstream-sleep and wakeable-park workers
check the same update identity and empty queue after removal. Four warm-up pairs
precede 20 alternating measured pairs. Output reports actual arrival time and
publication-start-to-pop latency. Local Linux medians were 45.181 ms upstream and
0.199 ms wakeable.
Hosted medians and nearest-rank p95 over 20 measured trials:
| Platform | Upstream median | Wakeable median | Wakeable p95 | Wakeable maximum |
| --- | ---: | ---: | ---: | ---: |
| macOS ARM64 | 84.273 ms | 0.068 ms | 0.103 ms | 16.096 ms |
| Linux x64 | 45.065 ms | 0.053 ms | 0.073 ms | 0.073 ms |
| Windows x64 | 45.159 ms | 0.074 ms | 0.127 ms | 0.182 ms |
The upstream Mac maximum was 108.892 ms; its requested 50 ms sleep overshot.
The wakeable Mac maximum also shows scheduler variability. The hosted ARM Mac
has three logical CPUs and is not the user's M2 Pro. [Raw trials](../benchmarks/idle-queue-2026-10-03)
are from [CI run 37155695460](https://github.com/ludovic111/minecraft-optimization-lab/actions/runs/37155695460).
This isolates idle wakeup, including enqueue/pop overhead. It does not simulate
the existing 250 ms debounce, preprocessing, chunk generation, meshing, network
delivery or a visible block update. Those delays remain separate. OS scheduling
can change latency; this is not an FPS measurement or a hard responsiveness bound.
Concurrency tests cover arrival before park, arrival while parked, pending
interrupts and interruption while parked. The runtime hook still requires exact
DH 3.3.4 and is enabled only with the existing queue experiment.
## Isolated measurement
Run `python -c "from tools.build_mod import benchmark_debounce; benchmark_debounce()"`
+14
View File
@@ -22,6 +22,20 @@ Version 0.2.0 targets Minecraft 26.3 / Fabric 0.19.5 / Java 25. This is an initi
## Interpretation limits
The exact 0.9.0 JAR (SHA-256
`2c5a731d4c93df427cc6054f120a52bf9456b3343b94ad9b79de1584b14d783f`)
ran the combined queue/adaptive/pacing profile with a 3 GiB heap and compact
headers enabled. Thread inspection reached the new wakeable idle park in all
three dimension queues. The 120-second capture produced 806 frame intervals and
2,411 server ticks, with matching CSV counts/means and 120 RSS samples each.
The frame report captures the idle hook as true and actual render/simulation
distances 12/12. The offline viewer reads the new flag, JVM settings and raw CSV;
general viewer checks also pass. World/database/worker shutdown completed cleanly.
Concurrency tests and the actual publisher-queue wake-latency probe pass on
Linux, Windows and hosted Apple Silicon macOS; [raw results and limits](debounce-queue.md)
keep idle wakeup separate from terrain completion and FPS. A 3 GiB heap passing
this short world test is not a recommendation for heavy or long-running worlds.
The exact 0.8.0 JAR (SHA-256
`b674be112cd148406b6b79c14f54b91a4da1ac0e03fe744aaee857c5a51eae8a`)
loaded the complete adaptive-queue stack with compact headers enabled. A fresh
@@ -0,0 +1,15 @@
package dev.horizonlab.budget;
import java.util.concurrent.locks.LockSupport;
/** A bounded idle park, preserving Thread.sleep's InterruptedException/cleared-flag contract. */
public final class WakeableIdleWait {
private WakeableIdleWait() { }
public static void pause(Object blocker, long nanoseconds) throws InterruptedException {
if (nanoseconds < 0) throw new IllegalArgumentException("Negative idle wait");
if (Thread.interrupted()) throw new InterruptedException();
LockSupport.parkNanos(blocker, nanoseconds);
if (Thread.interrupted()) throw new InterruptedException();
}
}
@@ -93,6 +93,7 @@ public final class HorizonClient implements ClientModInitializer {
context.put("adaptive_budget_enabled", terrainBudget != null);
context.put("precise_worker_pacing", dev.horizonlab.mixin.HorizonMixinPlugin.workerPacingEnabled());
context.put("debounce_queue_wait", dev.horizonlab.mixin.HorizonMixinPlugin.debounceWaitEnabled());
context.put("wakeable_idle_wait", dev.horizonlab.mixin.HorizonMixinPlugin.debounceWaitEnabled());
context.put("adaptive_target_fps", targetFps);
context.put("render_distance", client.options.renderDistance().get());
context.put("simulation_distance", client.options.simulationDistance().get());
@@ -5,6 +5,7 @@ import com.seibel.distanthorizons.core.api.internal.chunkUpdating.ChunkUpdateDat
import com.seibel.distanthorizons.core.api.internal.chunkUpdating.ChunkUpdateQueueManager;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
import dev.horizonlab.budget.DebounceWait;
import dev.horizonlab.budget.WakeableIdleWait;
import java.util.concurrent.locks.LockSupport;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@@ -21,10 +22,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public abstract class DhDebounceWaitMixin {
@Shadow @Final public ChunkPosQueue preUpdateQueue;
@Unique private volatile Thread horizonQueueWorker;
@Unique private long horizonLastIdleCleanup;
@Inject(method = "runQueueingLoop", at = @At("HEAD"), remap = false)
private void horizonRememberWorker(CallbackInfo callback) {
horizonQueueWorker = Thread.currentThread();
horizonLastIdleCleanup = System.nanoTime();
}
@Inject(method = "runQueueingLoop", at = @At("RETURN"), remap = false)
@@ -32,6 +35,28 @@ public abstract class DhDebounceWaitMixin {
horizonQueueWorker = null;
}
@Redirect(method = "runQueueingLoop", at = @At(value = "INVOKE",
target = "Ljava/lang/Thread;sleep(J)V"), require = 1, allow = 1, remap = false)
private void horizonWakeableIdle(long milliseconds) throws InterruptedException {
if (milliseconds != 50 || Thread.currentThread() != horizonQueueWorker) {
Thread.sleep(milliseconds);
return;
}
long remaining = 50_000_000L - (System.nanoTime() - horizonLastIdleCleanup);
WakeableIdleWait.pause(this, Math.max(0, remaining));
}
// Early wakeups must not turn the former 50 ms maintenance cadence into per-arrival work.
@Redirect(method = "runQueueingLoop", at = @At(value = "INVOKE",
target = "Lcom/google/common/cache/Cache;cleanUp()V"), require = 1, allow = 1, remap = false)
private void horizonBoundIdleMaintenance(com.google.common.cache.Cache<?, ?> cache) {
long now = System.nanoTime();
if (Thread.currentThread() != horizonQueueWorker || now - horizonLastIdleCleanup >= 50_000_000L) {
cache.cleanUp();
horizonLastIdleCleanup = System.nanoTime();
}
}
// Ordinal zero is specifically the debounce retry. Executor rejection retries remain unchanged.
@Redirect(method = "tryDispatchReadyChunkUpdate", at = @At(value = "INVOKE",
target = "Lcom/seibel/distanthorizons/core/api/internal/chunkUpdating/ChunkPosQueue;addItem(Lcom/seibel/distanthorizons/core/pos/DhChunkPos;Lcom/seibel/distanthorizons/core/api/internal/chunkUpdating/ChunkUpdateData;)V",
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "horizonlab",
"version": "0.8.0",
"version": "0.9.0",
"name": "Horizon Lab",
"description": "Client frame pacing and server tick measurements for reproducible optimization experiments.",
"authors": [
@@ -0,0 +1,63 @@
package dev.horizonlab.budget;
import com.seibel.distanthorizons.core.api.internal.chunkUpdating.ChunkPosQueue;
import com.seibel.distanthorizons.core.api.internal.chunkUpdating.ChunkUpdateData;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
import java.util.Locale;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.LockSupport;
/** Isolates wakeup after synthetic incoming work; does not measure terrain rendering or debounce. */
public final class IdleQueueBenchmark {
private static void run(boolean wakeable, boolean report, int trial) throws Exception {
var queue = new ChunkPosQueue();
var update = new ChunkUpdateData(null, null);
var ready = new CountDownLatch(1);
var published = new AtomicLong();
var idleStarted = new AtomicLong();
var latency = new AtomicLong();
var failure = new AtomicReference<Throwable>();
Thread worker = new Thread(() -> {
try {
idleStarted.set(System.nanoTime());
ready.countDown();
while (queue.isEmpty()) {
if (wakeable) WakeableIdleWait.pause(queue, 50_000_000L);
else Thread.sleep(50);
}
var item = queue.popClosest();
latency.set(System.nanoTime() - published.get());
if (item != update || queue.getQueuedCount() != 0)
throw new AssertionError("Queued work identity/count changed");
} catch (Throwable error) { failure.set(error); }
}, "Horizon idle queue benchmark");
worker.setDaemon(true);
worker.start();
try {
if (!ready.await(5, TimeUnit.SECONDS)) throw new AssertionError("Worker did not start");
LockSupport.parkNanos(5_000_000L);
long start = System.nanoTime();
published.set(start);
queue.addItem(new DhChunkPos(0, 0), update);
if (wakeable) LockSupport.unpark(worker);
worker.join(5_000);
if (worker.isAlive()) throw new AssertionError("Incoming work did not reach worker");
if (failure.get() != null) throw new AssertionError("Worker failed", failure.get());
if (latency.get() < 0) throw new AssertionError("Invalid timestamp ordering");
if (report) System.out.printf(Locale.ROOT,
"mode=%s trial=%d incoming_after_idle_ms=%.3f publication_to_pop_ms=%.3f%n",
wakeable ? "wakeable" : "upstream", trial, (start - idleStarted.get()) / 1e6, latency.get() / 1e6);
} finally {
worker.interrupt();
worker.join(1_000);
}
}
public static void main(String[] args) throws Exception {
for (int warmup = 0; warmup < 4; warmup++) { run(false, false, warmup); run(true, false, warmup); }
for (int trial = 0; trial < 20; trial++) { run(false, true, trial); run(true, true, trial); }
}
}
@@ -0,0 +1,70 @@
package dev.horizonlab.budget;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.LockSupport;
public final class WakeableIdleWaitTest {
private static void check(boolean condition, String message) {
if (!condition) throw new AssertionError(message);
}
private static void workerCase(boolean interrupt, boolean beforePark) throws Exception {
var ready = new CountDownLatch(1);
var proceed = new AtomicBoolean(!beforePark);
var failure = new AtomicReference<Throwable>();
var completed = new AtomicBoolean();
Thread worker = new Thread(() -> {
ready.countDown();
// No blocking operation may consume the early unpark permit before the tested wait.
while (!proceed.get() && !Thread.currentThread().isInterrupted()) Thread.onSpinWait();
try {
WakeableIdleWait.pause(completed, TimeUnit.SECONDS.toNanos(30));
check(!interrupt, "Interrupt must throw");
completed.set(true);
} catch (InterruptedException expected) {
if (!interrupt) failure.set(expected);
else if (Thread.currentThread().isInterrupted()) failure.set(new AssertionError("Throw must clear interrupt status"));
else completed.set(true);
} catch (Throwable error) { failure.set(error); }
}, "Horizon idle-wait test");
worker.setDaemon(true);
worker.start();
try {
check(ready.await(5, TimeUnit.SECONDS), "Worker did not start");
if (!beforePark) {
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(5);
while (worker.getState() != Thread.State.TIMED_WAITING && worker.isAlive() && System.nanoTime() < deadline)
Thread.onSpinWait();
check(worker.getState() == Thread.State.TIMED_WAITING, "Worker did not park");
}
if (interrupt) worker.interrupt(); else LockSupport.unpark(worker);
proceed.set(true);
worker.join(5_000);
check(!worker.isAlive(), "Wakeup was lost or shutdown stalled");
if (failure.get() != null) throw new AssertionError("Worker failed", failure.get());
check(completed.get(), "Wait did not complete");
} finally {
proceed.set(true);
worker.interrupt();
worker.join(1_000);
}
}
public static void main(String[] args) throws Exception {
Thread.currentThread().interrupt();
try {
WakeableIdleWait.pause(null, 1_000_000);
throw new AssertionError("Pending interrupt must throw");
} catch (InterruptedException expected) {
check(!Thread.currentThread().isInterrupted(), "Pending interrupt must be cleared");
}
workerCase(false, true); // Producer arrived between empty check and park.
workerCase(false, false); // Producer arrived while worker was idle.
workerCase(true, true);
workerCase(true, false);
System.out.println("Wakeable idle-wait arrival races and interruption tests passed.");
}
}
+2
View File
@@ -46,6 +46,8 @@ PROFILES
retries while a DH update is still inside its existing 250 ms debounce period.
Incoming work wakes the queue worker. OS timers can overshoot the requested
1 ms maximum wait; evaluate terrain update latency as well as CPU/FPS.
Version 0.9 also lets incoming work wake an empty queue's former 50 ms sleep.
Cache maintenance keeps its 50 ms cadence; the original debounce stays intact.
- adaptive-queue: combines queue-wait with adaptive terrain and precise pacing.
For an isolated comparison use queue-wait versus m2-balanced. For the combined
controls use adaptive-queue versus adaptive-pacing. Disable the queue hook in
+1 -1
View File
@@ -3,7 +3,7 @@
"minecraft": "26.3",
"java_major": 25,
"fabric_loader": "0.19.5",
"pack_version": "0.8.0",
"pack_version": "0.9.0",
"options_data_version": 5023,
"projects": {
"sodium": {
+1
View File
@@ -100,6 +100,7 @@ function renderDetails(side){
const r=entry.report,fields=[['Profile',r.profile||r.label||'Unlabeled'],['Recording',format(r.elapsed_seconds)+' s · '+format(r.stats.count)+' samples'],['Platform',[r.os,r.architecture].filter(Boolean).join(' ')||'Not captured']];
if(r.kind==='frames')fields.push(['Graphics',[r.gpu,r.graphics_backend].filter(Boolean).join(' · ')||'Not captured'],['Window',number(r.framebuffer_width)?r.framebuffer_width+' × '+r.framebuffer_height:'Not captured'],['Experiments','Adaptive: '+(r.adaptive_budget_enabled?'on':'off')+' · precise pacing: '+(r.precise_worker_pacing?'on':'off')+' · queue wait: '+(r.debounce_queue_wait?'on':'off')]);
fields.push(['JVM', 'Compact headers: '+(r.compact_object_headers===true?'on':r.compact_object_headers===false?'off':'not captured')+' · GC: '+(Array.isArray(r.garbage_collectors)?r.garbage_collectors.join(', '):'not captured')]);
fields.push(['Wakeable queue idle', r.wakeable_idle_wait===true?'on':r.wakeable_idle_wait===false?'off':'not captured']);
for(const [label,value]of fields)target.append(text('dt',label),text('dd',value));
}
async function loadFiles(side,files){
+21
View File
@@ -43,6 +43,10 @@ def test_metrics():
SOURCE / "test/java/dev/horizonlab/budget/DebounceWaitTest.java"]
subprocess.run(["javac", "--release", "25", "-d", str(destination), *map(str, debounce_sources)], check=True)
subprocess.run(["java", "-cp", str(destination), "dev.horizonlab.budget.DebounceWaitTest"], check=True)
idle_sources = [SOURCE / "main/java/dev/horizonlab/budget/WakeableIdleWait.java",
SOURCE / "test/java/dev/horizonlab/budget/WakeableIdleWaitTest.java"]
subprocess.run(["javac", "--release", "25", "-d", str(destination), *map(str, idle_sources)], check=True)
subprocess.run(["java", "-cp", str(destination), "dev.horizonlab.budget.WakeableIdleWaitTest"], check=True)
def build():
@@ -167,6 +171,23 @@ def benchmark_headers():
print(output.read_text(), end="")
def benchmark_idle():
arguments = [json.loads(line) for line in (BUILD / "javac.args").read_text().splitlines()]
classpath = os.pathsep.join([str(BUILD / "classes"), arguments[arguments.index("-classpath") + 1]])
tests = BUILD / "idle-benchmark"
tests.mkdir(parents=True, exist_ok=True)
subprocess.run(["javac", "--release", "25", "-proc:none", "-cp", classpath,
"-d", str(tests), str(SOURCE / "test/java/dev/horizonlab/budget/IdleQueueBenchmark.java")], check=True)
output = ROOT / "dist/idle-queue-benchmark.txt"
with output.open("w", encoding="utf-8") as report:
report.write(f"Java {subprocess.check_output(['java', '--version'], text=True).splitlines()[0]}\n")
report.write(f"Platform {platform.system()} {platform.release()} {platform.machine()}; logical CPUs {os.cpu_count()}\n")
report.flush()
subprocess.run(["java", "-cp", os.pathsep.join([str(tests), classpath]),
"dev.horizonlab.budget.IdleQueueBenchmark"], stdout=report, check=True)
print(output.read_text(), end="")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--test-only", action="store_true")