perf(core): apply code-review optimizations for latency, allocations and concurrency

- LogBuffer: add revision counter and sync only latest 50 entries when revision changes, eliminating ~180k heap string allocations/sec.
- Engine: move dome_lut.apply outside of latest_frame lock guard to prevent GStreamer appsink thread contention.
- Video: reuse existing Vec buffer in appsink callback, render standby pattern in-place to avoid 3.7MB/frame alloc.
- GPUI: remove premature texture drain on idle ticks, spawn background threads for bash/ssh scripts to avoid zombie processes.
- Nomad: add NaN guard in deg_to_crsf, track last_send_ok to prevent permanent error state latch, add CRSF packet & CRC8 unit tests.
- OpenXR/Engine: enforce Acquire/Release ordering on atomic control flags, join worker thread reliably on stop.
This commit is contained in:
bleackstorm committed 2026-11-05 21:46:14 +01:00
1 parent 0fbe184716
commit 5d81993bbe
6 files changed
+140 -73

No files matched your search

+19 -3
View File
@@ -21,6 +21,7 @@ pub struct HeadPoseSample {
pub roll_crsf: u16,
pub packets_sent: u64,
pub send_errors: u64,
pub last_send_ok: bool,
}
impl Default for HeadPoseSample {
@@ -34,6 +35,7 @@ impl Default for HeadPoseSample {
roll_crsf: CRSF_CHANNEL_MID,
packets_sent: 0,
send_errors: 0,
last_send_ok: false,
}
}
}
@@ -131,9 +133,10 @@ impl NomadHeadTracker {
self.socket.send_to(&packet, self.target)
};
match send_res {
let last_send_ok = match send_res {
Ok(_) => {
self.packets_sent = self.packets_sent.wrapping_add(1);
true
}
Err(e) => {
self.send_errors = self.send_errors.wrapping_add(1);
@@ -149,8 +152,9 @@ impl NomadHeadTracker {
);
self.last_error_log = Some(Instant::now());
}
false
}
}
};
Ok(HeadPoseSample {
pan_deg,
@@ -161,12 +165,13 @@ impl NomadHeadTracker {
roll_crsf,
packets_sent: self.packets_sent,
send_errors: self.send_errors,
last_send_ok,
})
}
#[inline]
pub fn deg_to_crsf(angle_deg: f32, max_deg: f32) -> u16 {
if max_deg <= 0.0 {
if angle_deg.is_nan() || max_deg <= 0.0 {
return CRSF_CHANNEL_MID;
}
let norm = (angle_deg / max_deg).clamp(-1.0, 1.0);
@@ -248,6 +253,7 @@ mod tests {
assert_eq!(NomadHeadTracker::deg_to_crsf(0.0, 90.0), CRSF_CHANNEL_MID);
assert_eq!(NomadHeadTracker::deg_to_crsf(90.0, 90.0), CRSF_CHANNEL_MAX);
assert_eq!(NomadHeadTracker::deg_to_crsf(-90.0, 90.0), CRSF_CHANNEL_MIN);
assert_eq!(NomadHeadTracker::deg_to_crsf(f32::NAN, 90.0), CRSF_CHANNEL_MID);
}
#[test]
@@ -256,5 +262,15 @@ mod tests {
assert_eq!(&pkt[0..3], b"$X<");
assert_eq!(u16::from_le_bytes([pkt[4], pkt[5]]), MSP_ELRS_BACKPACK_SET_PTR);
assert_eq!(u16::from_le_bytes([pkt[6], pkt[7]]), 6);
assert_eq!(pkt[14], NomadHeadTracker::crc8_dvb_s2(&pkt[3..14]));
}
#[test]
fn test_crsf_rc_channels_packet() {
let pkt = NomadHeadTracker::encode_crsf_rc_channels(992, 992, 992);
assert_eq!(pkt[0], 0xEE); // Sync CRSF
assert_eq!(pkt[1], 24); // Payload len
assert_eq!(pkt[2], 0x16); // Type RC_CHANNELS_PACKED
assert_eq!(pkt[25], NomadHeadTracker::crc8_dvb_s2(&pkt[2..25]));
}
}