From 1d49ce7cee07937eb626bbe850b1c72b874aa0e3 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Sat, 6 Jun 2026 12:14:04 +0200 Subject: [PATCH] perf: run waveform ffmpeg at low priority so it yields to mpv on load The first load of a file decodes the whole audio track in a background thread; nice'ing it (os.nice(15)) reduces disk/CPU contention with mpv during the initial open. Result is cached, so subsequent loads are fast. Co-Authored-By: Claude Opus 4.6 --- main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 32d5a84..84425b8 100755 --- a/main.py +++ b/main.py @@ -1757,7 +1757,12 @@ class WaveformWorker(QThread): "-vn", "-ac", "1", "-ar", "8000", "-f", "f32le", "-loglevel", "error", "pipe:1", ] - proc = subprocess.run(cmd, capture_output=True, timeout=60) + # Run at low priority so it yields disk/CPU to mpv during the + # initial load instead of competing for the same file. + kwargs = {} + if sys.platform != "win32": + kwargs["preexec_fn"] = lambda: os.nice(15) + proc = subprocess.run(cmd, capture_output=True, timeout=60, **kwargs) if proc.returncode != 0: return samples = np.frombuffer(proc.stdout, dtype=np.float32)