From b9ae1990e827f66bbf9b6d6e2abd9eb41fe33ecd Mon Sep 17 00:00:00 2001 From: Brendan Robert Date: Fri, 15 Mar 2024 10:32:01 -0500 Subject: [PATCH] Changed timing strategy, got ~2x better performance --- .../main/java/jace/core/IndependentTimedDevice.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Platform/Apple/tools/jace/src/main/java/jace/core/IndependentTimedDevice.java b/Platform/Apple/tools/jace/src/main/java/jace/core/IndependentTimedDevice.java index 383ad164..d19b2684 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/core/IndependentTimedDevice.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/core/IndependentTimedDevice.java @@ -100,10 +100,20 @@ public abstract class IndependentTimedDevice extends TimedDevice { } } + public static int SLEEP_PRECISION_LIMIT = 100; public void sleepUntil(Long time) { if (time != null) { while (System.nanoTime() < time) { - Thread.onSpinWait(); + int waitTime = (int) ((time - System.nanoTime()) / 1000000); + if (waitTime >= SLEEP_PRECISION_LIMIT) { + try { + Thread.sleep(waitTime); + } catch (InterruptedException ex) { + return; + } + } else { + Thread.onSpinWait(); + } } } }