perf(menubar): 隔离卡片动效并推进 1.1 低开销版本
This commit is contained in:
@@ -16,6 +16,10 @@ final class MetricsStore {
|
||||
private var panelDemand: Bool { isPanelVisible && !isDisplaySleeping }
|
||||
var effectiveMilliseconds: Int { panelDemand ? sampling.panelMilliseconds : sampling.backgroundMilliseconds }
|
||||
private var hasSamplingDemand: Bool { !isSystemSleeping && (panelDemand || sampling.backgroundEnabled) }
|
||||
// Permit timer coalescing without changing the requested cadence or delta timestamps.
|
||||
private var schedulingTolerance: Duration {
|
||||
.milliseconds(min(effectiveMilliseconds / 10, panelDemand ? 200 : 1_000))
|
||||
}
|
||||
@ObservationIgnored private var generation = 0
|
||||
@ObservationIgnored private var visibilityGeneration = 0
|
||||
@ObservationIgnored private var task: Task<Void, Never>?
|
||||
@@ -59,7 +63,7 @@ final class MetricsStore {
|
||||
task = Task { [weak self, sampler] in
|
||||
guard !Task.isCancelled else { return }
|
||||
if initialDelay > .zero {
|
||||
do { try await Task.sleep(for: initialDelay) } catch { return }
|
||||
do { try await Task.sleep(for: initialDelay, tolerance: self?.schedulingTolerance) } catch { return }
|
||||
}
|
||||
if reset { await sampler.reset() }
|
||||
while !Task.isCancelled {
|
||||
@@ -98,7 +102,7 @@ final class MetricsStore {
|
||||
let interval = self?.effectiveMilliseconds ?? 5_000
|
||||
// Start-to-start cadence; missed deadlines do not trigger catch-up bursts.
|
||||
let deadline = sampledAt.advanced(by: .milliseconds(interval))
|
||||
do { try await Task.sleep(until: max(deadline, .now), clock: .continuous) }
|
||||
do { try await Task.sleep(until: max(deadline, .now), tolerance: self?.schedulingTolerance, clock: .continuous) }
|
||||
catch { return }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user