Rudder was measured slowing after about 1,400 words while a Tauri build ran. The word count is incidental — it is a proxy for how long the build had been going. The speech model runs on the CPU (backend/rudder-engine starts it with --device cpu), and a Rust build saturates every core, so at equal priority it starves the one process whose latency a person can hear. Three changes, and the direction of the first is forced rather than chosen: 1. internal/desktop-build.mjs nices the whole build tree to 10, through the one run() helper every step goes through, so cargo, rustc and the linker inherit it. We nice the COMPETITOR because an unprivileged process cannot raise its own priority on Linux — a negative nice needs CAP_SYS_NICE — so "promote the ASR" would fail with EPERM. If nice(1) is missing the build still runs and says so, because a silent fallback would look exactly like the fix working. 2. cargo is capped at cores-1. nice decides who wins a CONTESTED core; it does not stop the build taking all of them, and a fully subscribed machine still adds scheduling latency to the audio path. An explicit CARGO_BUILD_JOBS is honoured rather than overridden. 3. yieldCPU reports its error instead of discarding it. It was `_ = syscall.Setpriority(...)`, which cannot fail visibly — a call that silently does nothing is indistinguishable from one that worked, and this one guards something audible. Also, one real O(n) in the widget, found while checking studio's answer that the collapsed pill already shows the last words: sendActivity split the ENTIRE draft on every activity tick to take five words. Measured at 3,000 words: 1.61ms per tick against 0.051ms for a bounded tail, 31x, with byte-identical output. Verify the priority work with `ps -o ni=` on the running cargo processes, never by any of these calls returning.
33 lines
1.6 KiB
Go
33 lines
1.6 KiB
Go
//go:build linux
|
|
|
|
package main
|
|
|
|
import (
|
|
"log"
|
|
"syscall"
|
|
)
|
|
|
|
// childAttr: a child process (the speech server, a recorder) is killed with the engine, so a crash
|
|
// never leaves a speech server holding a gigabyte of memory. Linux only: Pdeathsig does not exist on
|
|
// macOS or Windows (see procattr_other.go).
|
|
func childAttr() *syscall.SysProcAttr {
|
|
return &syscall.SysProcAttr{Pdeathsig: syscall.SIGKILL}
|
|
}
|
|
|
|
// yieldCPU lowers a background helper's CPU priority (nice 10), so on a thin client the live transcription
|
|
// always wins the CPU over it. Used for the robot voice: its ~1 s burst per sentence must never make the
|
|
// words you are speaking fall behind.
|
|
//
|
|
// ★ RAISING a priority is NOT available here and must not be attempted: an unprivileged process cannot
|
|
// set a negative nice (that needs CAP_SYS_NICE), so the call would fail with EPERM. Lowering — which is
|
|
// what this does — needs no privilege. The direction matters: the fix for a build starving dictation is
|
|
// to nice the BUILD, not to promote the engine (internal/desktop-build.mjs does that).
|
|
//
|
|
// The error is REPORTED rather than discarded. It was `_ = syscall.Setpriority(...)`, which cannot fail
|
|
// visibly: a call that silently does nothing looks exactly like a call that worked, and this one guards
|
|
// something a person can hear. Verify with `ps -o ni=` on the pid, never by this returning.
|
|
func yieldCPU(pid int) {
|
|
if err := syscall.Setpriority(syscall.PRIO_PROCESS, pid, 10); err != nil {
|
|
log.Printf("rudder: could not lower pid %d to nice 10 (%v); the robot voice will compete with live transcription", pid, err)
|
|
}
|
|
}
|