feat(client/present): Apple reads the cadence statistic — WP1 complete
The third and last leg of WP1. All three clients now publish the same
judder number, which was the point: one ruler, so a smoothness A/B can be
compared across platforms instead of argued about.
A verbatim Swift port of punktfunk_core::phase::PresentIntervals, in the
same spirit as PhaseReporter.circularLatch alongside it, with a test file
that runs the SAME vectors as the Rust unit tests. A hand-written port is
exactly where "all three emit the same numbers" quietly stops being true,
so it is pinned rather than trusted.
Porting it found a real cross-client hazard. The modal spacing was read
with max_by_key, which returns the LAST maximum, while Swift's max(by:)
returns the FIRST — so a 50/50 window (the classic 1-and-3 sawtooth) would
have reported the same judder but a different mode on Android and Apple.
Both sides now spell the rule out: ties resolve to the smallest spacing.
The Rust test that previously accepted either answer now pins it.
Two Apple-specific decisions:
- the stats object is built for EVERY session, not just under the debug
env var or deadline pacing. A smoothness defect produces no drops and
healthy percentiles, so gating the one statistic that could see it
behind an env var means it is off exactly when it matters. A `verbose`
flag preserves the old behaviour for the wordy counters line; the
cadence line always emits.
- the panel period comes from the link's own reported period (glass
pacing) or is learned from the link's target instants (deadline
pacing). Those tick at the panel rate whether or not WE present, which
is what makes the window minimum the true period — the same reasoning
PhaseReporter already documents. Learning it from on-glass spacings
instead would read a 60-on-120 stream as a 60 Hz panel and mislabel the
cadence mode.
A dropped drawable splits the run rather than scoring the gap: it never
reached glass, so it is not a cadence event, and the next present does not
continue the previous interval either.
Gates: punktfunk-core 21 phase tests green; the Swift port verified against
all 11 Rust vectors via a standalone harness (identical mode/judder/samples/
stalls/disordered on every case, incl. the tie-break); both edited Swift
files parse clean; fmt clean.
⚠ The Swift INTEGRATION is not compiler-verified locally: building
PunktfunkCore.xcframework on this machine fails a pre-existing deployment-
target guard (objects at minos 26 survive a cache wipe and an exported
MACOSX_DEPLOYMENT_TARGET). Source-only change, so it cannot be the cause.
CI's Apple leg owns that check — treat it as owed, not passed.
This commit is contained in:
@@ -234,12 +234,18 @@ impl PresentIntervals {
|
||||
if self.samples < CADENCE_MIN_SAMPLES {
|
||||
return None;
|
||||
}
|
||||
let (mode_units, mode_count) = self
|
||||
.hist
|
||||
.iter()
|
||||
.enumerate()
|
||||
.max_by_key(|&(_, c)| *c)
|
||||
.map(|(i, &c)| (i as u8, c))?;
|
||||
// Ties resolve to the SMALLEST spacing, spelled out rather than left to a library:
|
||||
// `max_by_key` would take the last maximum and Swift's `max(by:)` the first, so a
|
||||
// 50/50 window (the classic 1-and-3 sawtooth) would label its mode differently on
|
||||
// Android and Apple while reporting the same judder. The clients have to agree.
|
||||
let mut mode_units = 0u8;
|
||||
let mut mode_count = 0u32;
|
||||
for (i, &c) in self.hist.iter().enumerate() {
|
||||
if c > mode_count {
|
||||
mode_count = c;
|
||||
mode_units = i as u8;
|
||||
}
|
||||
}
|
||||
Some(PresentCadence {
|
||||
mode_units,
|
||||
judder_permille: (u64::from(self.samples - mode_count) * 1000 / u64::from(self.samples))
|
||||
@@ -474,7 +480,10 @@ mod cadence_tests {
|
||||
fn the_sawtooth_that_latency_stats_cannot_see() {
|
||||
let s = cadence(&[P, P * 3], 40).summary().unwrap();
|
||||
assert_eq!(s.judder_permille, 500);
|
||||
assert!(matches!(s.mode_units, 1 | 3));
|
||||
assert_eq!(
|
||||
s.mode_units, 1,
|
||||
"a tied mode resolves to the smallest spacing — pinned so the Swift port agrees"
|
||||
);
|
||||
}
|
||||
|
||||
/// Sub-refresh jitter is not judder: the display quantises it away, so the metric must too.
|
||||
|
||||
Reference in New Issue
Block a user