Skip to content

7Climb v3.0.2

Latest

Choose a tag to compare

@yrkan yrkan released this 04 Mar 20:18
· 1 commit to main since this release

Critical fix

Sensor emission batching to 1Hz — All 8 sensor callbacks (power, HR, cadence, speed, altitude, grade, distance, GPS) previously called emitState() independently, creating ~8 emissions/second. Since each emission carried a fresh timestamp, StateFlow never deduplicated — all downstream engines fired on every callback.

This caused:

  • ~8x overcounting of energy (kJ), Normalized Power, TSS, and match burn durations — MetricsEngine and MatchBurnEngine assumed 1 call = 1 second
  • ~8x CPU overhead — PacingCalculator ran 20 Newton iterations with trig per call, all 6 engines processed redundantly

Now a single 1Hz timer emits state, and a sensorUpdatedSinceLastEmit guard prevents stale emissions during ride pause (which would inflate kJ/NP/TSS with phantom power data).

Performance improvements

  • TacticalAnalyzer caching — getPrimaryInsight() was called 14×/sec (once per data field per second), each time rebuilding all insights with list allocations and sorting. Now cached with 1% progress threshold — recomputes only when the rider moves meaningfully along the climb.

  • MetricsEngine running NP sum — Replaced npWindow.sum() (O(30) per tick) with a running sum variable (O(1)).

  • PacingCalculator physics cache — calculateTargetPower() runs speedFromPower() (Newton iterations with atan/sin/cos/exp) every tick. Now cached when grade (±0.1%), altitude (±5m), FTP, mode, and athlete profile haven't changed. On a steady 7% climb, physics runs once on entry instead of 3600×/hour.

  • PowerZonesGlance composable reduction — Zone bar segments reduced from 20 to 10 in ZonesLarge, ZoneBar, and ProgressBar. 140 → 70 Box composables in the largest layout. Visual difference negligible at Karoo display sizes.

  • ClimbDetector ArrayDeque — Replaced mutableListOf with ArrayDeque for O(1) removeFirst() instead of O(n) removeAt(0). Replaced takeLast(N).average() (temporary list allocation) with index-based iteration.

  • PhysicsUtils solver — Newton iterations reduced from 20 to 10, convergence tolerance from 0.1W to 1.0W. 1W precision is more than sufficient for pacing advice.

Minor improvements

  • Cached activeClimb.value read in extension's main data flow (1 StateFlow read instead of 2 per tick)
  • Removed unnecessary @Serializable annotations from 7 transient model classes (LiveClimbState, WPrimeState, ClimbStats, RideMetrics, PacingTarget, MatchBurnState/Match, NextClimbInfo) — none are ever serialized
  • Defensive emitJob?.cancel() at start of startStreaming() prevents duplicate timers on Karoo reconnect edge case

Behavioral note

MatchBurnEngine's belowCpCounter >= 5 threshold now means 5 real seconds below CP (previously ~0.6s at 8Hz). This is an improvement: brief power dips during intervals no longer prematurely end a match, matching industry-standard match burn detection behavior.