You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf: cache LocalStatsLog derived data instead of refetching per render
LocalStatsLog read `localStats` (a SwiftData fetch via node.safeTelemetries,
limit 500) through a chain of computed properties — chartData, noiseFloorReadings,
chartYDomain, chartDataDuration, chartVisibleDuration, chartXAxisFormat — plus
node.hasLocalStats (a fetchCount) and the Table. SwiftUI doesn't memoize computed
getters, so a single `body` pass fired ~8 fetches and repeated sorts.
The chart binds its scroll offset to @State via .chartScrollPosition(x:), so
`body` re-evaluates on every scroll frame — turning a chart scroll (or table
selection, or range change) into ~8 main-thread DB fetches + sorts per frame and
janking on nodes with many readings.
Compute the derived data once in refreshData() and cache it in @State
(localStats, noiseFloorReadings, chartYDomain, chartDataDuration). Refresh only on
appear, when node.lastHeard changes (new packets, incl. local-stats telemetry),
and after a clear — never from `body`. Scrolling now reuses the cached arrays with
zero fetches or sorts. Same pattern already used by NodeListItem.rowSummary and
DeviceHardwareImage.
Gates (chart/table vs ContentUnavailable, Clear/Save buttons) now read the cached
array instead of re-querying node.hasLocalStats each render.
0 commit comments