-
-
Notifications
You must be signed in to change notification settings - Fork 23
Frame interval calc possible optimization? #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -127,7 +127,7 @@ | |||||
| (def ^:private frame-count-for-load | ||||||
| "The number of frames to keep track of for calculating the current | ||||||
| load on the show." | ||||||
| 30) | ||||||
| 200) | ||||||
|
|
||||||
| (defn- update-stats | ||||||
| "Update the count of how many frames have been sent, total and | ||||||
|
|
@@ -138,14 +138,14 @@ | |||||
| total-time (+ duration (:total-time stats 0)) | ||||||
| frames-sent (inc (:frames-sent stats 0)) | ||||||
| average-duration (double (/ total-time frames-sent)) | ||||||
| recent (:recent stats (ring-buffer 30)) | ||||||
| recent (:recent stats (ring-buffer frame-count-for-load)) | ||||||
| discarding (if (< (count recent) frame-count-for-load) 0 (- (peek recent))) | ||||||
| recent (conj recent duration) | ||||||
| recent-total (+ (:recent-total stats 0) duration discarding) | ||||||
| recent-average (double (/ recent-total (count recent)))] | ||||||
| (when (> duration refresh-interval) | ||||||
| (taoensso.timbre/warn "Frame took" duration "ms to generate, refresh interval is" refresh-interval "ms.")) | ||||||
| (assoc stats :total-time total-time :frames-sent frames-sent :average-duration average-duration | ||||||
| (taoensso.timbre/warn "Frame took" duration "ms," (- duration refresh-interval) "ms overdue.")) | ||||||
| (assoc stats :total-time total-time :frames-sent frames-sent :average-duration average-duration :discarding discarding | ||||||
| :recent recent :recent-total recent-total :recent-average recent-average))) | ||||||
|
|
||||||
| (defn current-load | ||||||
|
|
@@ -326,14 +326,14 @@ | |||||
| (when (and @still-running @(:pool show)) ; We have not been shut down | ||||||
| (let [ended (at-at/now) | ||||||
| duration (- ended (:instant snapshot)) | ||||||
| sleep-time (math/round (max 1 (- (:refresh-interval show) duration))) | ||||||
| next-frame-snapshot (rhythm/metro-snapshot (:metronome show) (+ ended sleep-time))] | ||||||
| sleep-time (math/round (max 0 (- (:refresh-interval show) duration))) ;;if ends late, sleep-time is 0 (was 1) so next frame was actually attempted insanely early? if duration 10 sleep-time 15 it works, but duration 30 sleep-time 1 = 0, 30, 31... | ||||||
|
||||||
| next-frame-snapshot (rhythm/metro-snapshot (:metronome show) (+ ended (:refresh-interval show)))] ;or (+ ended (- (:refresh-interval show) duration)) to stay fully on clock... but unlikely to randomly manage to render next frame like, twice as fast as current. will have to judge what's feasible based on recent stats, active effects etc, and set a time | ||||||
|
||||||
| next-frame-snapshot (rhythm/metro-snapshot (:metronome show) (+ ended (:refresh-interval show)))] ;or (+ ended (- (:refresh-interval show) duration)) to stay fully on clock... but unlikely to randomly manage to render next frame like, twice as fast as current. will have to judge what's feasible based on recent stats, active effects etc, and set a time | |
| next-frame-snapshot (rhythm/metro-snapshot (:metronome show) (+ ended sleep-time))] ; use actual scheduled delay so snapshot time doesn't end up in the past when frames overrun |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional check when-not (zero? sleep-time) before calling Thread/sleep is unnecessary. Thread.sleep(0) is valid in Java and has well-defined behavior (it causes the thread to relinquish its current time slice to other threads). The original code's use of max 1 ensured at least 1ms sleep, which guaranteed context switching. With this change, when frames run late, the thread never yields, which could lead to CPU starvation of other threads or processes. Consider whether preventing the thread from ever yielding is the intended behavior.
| (when-not (zero? sleep-time) (Thread/sleep sleep-time)) | |
| (Thread/sleep sleep-time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
:discardingfield is added to the stats map but is never read or used anywhere in the codebase. This appears to be dead code. If this field was intended for debugging or monitoring purposes, consider removing it or documenting its purpose and adding code that actually uses it.