Skip to content

Interactive 2D wave optics simulator. Turn any image into a refractive scene, add sources, watch waves refract, diffract and interfere. Probes, intensity maps, video export.

C#

The run's heartbeat is posted at Loaded priority: the Live follow of a running run no longer stalls while the mouse moves

Alexander Graefb904fe43a764
diff --git a/CLAUDE.md b/CLAUDE.md
index 529cb84..0108a1e 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -271,7 +271,17 @@ FrameStore: native memory up to the budget, the rest in a temp file (%LOCALAPPDA
on the mouse showed it): a `DispatcherTimer` is a Win32 timer message, which Windows delivers only when no input is
queued, so a mouse reporting a thousand times a second starved the clock and no frame came for seconds (a gap of 3.2 s
measured under injected moves every millisecond; 63–87 ms at a move every 8 ms); a posted operation is taken before
- input, and the same flood now leaves gaps of 32–47 ms, 68 at a move every tenth of a millisecond. **The presenter's
+ input, and the same flood now leaves gaps of 32–47 ms, 68 at a move every tenth of a millisecond. **The run's
+ heartbeat is posted at Loaded priority** for the same reason (2026-11-04, the user's report: the Live follow of a
+ running run stuttered the same way): the dispatcher's background range is Background and Input, served only when no
+ input is pending, else through a 1 ms Win32 timer that queued input starves; at Background a flood of 4 s on Example 7
+ left the status at the step where the flood began, no picture came, and the run's Completed state landed 7 s after the
+ stepping ended; at Loaded, the lowest priority ahead of input, the follow went on at 100 frames in 3.3 s with a
+ worst gap of 71 ms, the status counting. Background had been chosen on 2026-10-16 against the opposite, keys and
+ clicks delivered after the run, when the progress was several posts a second each posted the moment the last was
+ handled; the one paced heartbeat leaves input its turn at any priority (RunCheck's 71 checks, which press keys
+ during a run, pass). The scene composition's coalescing and the debounce timers stay at Background: they are meant
+ to wait for the hand to rest. **The presenter's
log line carries the block's worst** beside its averages, the longest frame, the longest wait at the bitmap and the
longest gap between two presented frames: a stutter is a gap, which an average over 100 frames hides (it had shown 28
frames a second across a 3-second freeze). Measured on the way and settled: the app's input handling is not the cost,
diff --git a/WaveDudeNext.WPF/MainWindow.Simulation.cs b/WaveDudeNext.WPF/MainWindow.Simulation.cs
index 4ae2b43..4f4c49d 100644
--- a/WaveDudeNext.WPF/MainWindow.Simulation.cs
+++ b/WaveDudeNext.WPF/MainWindow.Simulation.cs
@@ -136,11 +136,16 @@ public partial class MainWindow
}
Task memoryReleased = DiscardRun();
FrameStore store = FrameStore.Create(FrameCache.NewPath(), spec.Shape, spec.Layers, spec.StoredFrameCount, spec.CaptureEvery, budget, memoryReleased);
- // the run's progress lands on the UI thread below input priority (2026-10-16): posted at normal priority, the
- // frame counts kept the input queue starved for the whole run, since a new one was posted the moment the last
- // was handled, and every click and key was delivered after the run (the watchdog's input-priority ticks were
- // late, the normal-priority ones on time)
- var run = new SimulationRun(spec, store, new DispatcherSynchronizationContext(Dispatcher, DispatcherPriority.Background), automatic);
+ // the run's progress lands on the UI thread at Loaded priority (2026-11-04): the lowest priority the dispatcher
+ // still processes ahead of queued input. Background and Input priority are its "background" range, which it
+ // serves only when no input is pending, else through a 1 ms Win32 timer, a message Windows delivers after every
+ // queued input message; a mouse reporting a thousand times a second kept input pending the whole time, so the
+ // heartbeat, the Live follow with it and the run's final state waited until the hand came off the mouse (a
+ // flood of 4 s left the status at the step where it started and the pictures still). The 2026-10-16 choice of
+ // Background had cured the opposite, every click and key delivered after the run, when the progress was posted
+ // at normal priority as separate posts, each the moment the last was handled; since the one paced heartbeat
+ // (at most 30 a second, a few milliseconds each) input has its turn between two of them at any priority
+ var run = new SimulationRun(spec, store, new DispatcherSynchronizationContext(Dispatcher, DispatcherPriority.Loaded), automatic);
run.PropertyChanged += (_, args) =>
{
if (args.PropertyName == nameof(SimulationRun.State))