perf(efficiency): 落实首批采样减负与发行包瘦身

This commit is contained in:
2026-11-03 23:19:52 +08:00
parent 935701fca6
commit def3b1e130
40 changed files with 483 additions and 291 deletions
-2
View File
@@ -5,7 +5,6 @@ struct CPUCoreGrid: View {
let values: [Double]
let kinds: [Int: CPUCoreTopology.Kind]
let interval: TimeInterval
@Environment(\.accessibilityReduceMotion) private var reduceMotion
private func color(_ kind: CPUCoreTopology.Kind?) -> Color {
switch kind {
@@ -93,7 +92,6 @@ struct CPUCoreGrid: View {
Circle().inset(by: 1).trim(from: 0, to: value)
.stroke(color(kind), style: StrokeStyle(lineWidth: 2, lineCap: .round))
.rotationEffect(.degrees(-90))
.animation(reduceMotion ? nil : .easeInOut(duration: min(0.35, interval * 0.8)), value: value)
Text(verbatim: "\(Int((value * 100).rounded()))")
.font(.system(size: 8, weight: .medium)).lineLimit(1).minimumScaleFactor(0.4)
}
@@ -6,7 +6,6 @@ struct GPUStatisticsView: View {
let allocated: UInt64?
let average: Double?
let peak: Double?
@Environment(\.accessibilityReduceMotion) private var reduceMotion
private var reference: Double { max(1, Double(max(inUse ?? 0, allocated ?? 0))) }
@@ -33,8 +32,6 @@ struct GPUStatisticsView: View {
}.font(PanelStyle.label).lineLimit(1)
MetricProgressBar(value: bytes.map { Double($0) / reference } ?? 0, color: color)
.frame(height: 3)
.animation(reduceMotion ? nil : .easeInOut(duration: 0.35), value: bytes)
.animation(reduceMotion ? nil : .easeInOut(duration: 0.35), value: reference)
.accessibilityHidden(true)
}
}
@@ -52,7 +52,8 @@ extension MenuPanelView {
}.font(PanelStyle.label)
.modifier(CardInset())
}
.task(id: publicIPRoute) {
.task(id: "\(publicIPRoute):\(metrics.isPaused)") {
guard !metrics.isPaused, metrics.isPanelVisible else { return }
publicIPAddress = nil
guard snapshot.networkPath == .available else { return }
await PublicIPAddressService.shared.refreshContinuously(route: publicIPRoute) { address in
@@ -109,7 +109,6 @@ extension MenuPanelView {
HStack(spacing: 8) {
Text(title).font(PanelStyle.label).frame(width: 100, alignment: .leading)
MetricProgressBar(value: value ?? 0, color: color).frame(height: 5)
.animation(reduceMotion ? nil : .easeInOut(duration: min(0.35, chartInterval * 0.8)), value: value)
AnimatedMetricText(value: MetricFormat.percent(value)).font(PanelStyle.value).frame(width: 30, alignment: .trailing)
}.font(PanelStyle.label)
}
@@ -286,7 +285,6 @@ struct EnergyProcessListRow: View {
.clipShape(Capsule())
}
.frame(height: 4)
.animation(.easeInOut(duration: 0.35), value: process.cpu)
AnimatedMetricText(value: process.cpu.map { String(format: "%.1f%%", $0 * 100) } ?? "--")
.foregroundStyle(Color("MetricCPU")).font(PanelStyle.value)
.monospacedDigit().frame(width: 39, alignment: .trailing)
+14 -10
View File
@@ -47,14 +47,14 @@ struct MenuPanelView: View {
var body: some View {
VStack(spacing: PanelStyle.gap) {
header
if PanelResourceAudit.omitted != "header" { header }
if PanelLayout.needsResourceScroll(size: panelSize, rows: rowHeights) {
ScrollView { resourceRows }
.frame(maxHeight: PanelLayout.resourceHeight(rows: rowHeights))
} else {
resourceRows
}
if metrics.isPanelVisible {
if metrics.isPanelVisible && PanelResourceAudit.omitted != "processes" {
ProcessTableView(snapshot: snapshot.processes, wide: panelSize.width >= 900).frame(maxWidth: .infinity, maxHeight: .infinity)
.frame(minHeight: 170)
}
@@ -98,14 +98,18 @@ struct MenuPanelView: View {
}
@ViewBuilder private func resourceCard(at index: Int) -> some View {
switch index {
case 0: cpuCard
case 1: gpuCard
case 2: batteryCard
case 3: memoryCard
case 4: diskCard
case 5: networkCard
default: EmptyView()
if PanelResourceAudit.omitted == "resources" {
Color.clear
} else {
switch index {
case 0: cpuCard
case 1: gpuCard
case 2: batteryCard
case 3: memoryCard
case 4: diskCard
case 5: networkCard
default: EmptyView()
}
}
}
@@ -0,0 +1,39 @@
import AppKit
/// Explicit local measurement only. Never schedules work during normal launches.
@MainActor enum PanelResourceAudit {
static let enabled = ProcessInfo.processInfo.environment["KYMO_RESOURCE_AUDIT"] == "1"
static let omitted = enabled ? ProcessInfo.processInfo.environment["KYMO_AUDIT_OMIT"] ?? "" : ""
static func run(controller: MenuPanelController, metrics: MetricsStore) {
guard enabled else { return }
Task { @MainActor in
@MainActor func mark(_ event: String) { SamplingDiagnostics.record(metrics.snapshot, event: "audit." + event) }
func wait(_ seconds: Int) async { try? await Task.sleep(for: .seconds(seconds)) }
// Pin the test window so unrelated focus changes cannot invalidate a measurement.
controller.presentation.isPinned = true
mark("cold")
await wait(10)
mark("hidden10")
for cycle in 1...3 {
controller.show()
mark("open\(cycle).0")
await wait(1); mark("open\(cycle).1")
await wait(9); mark("open\(cycle).10")
await wait(20); mark("open\(cycle).30")
if cycle == 1 {
metrics.togglePause(); mark("paused.0")
await wait(10); mark("paused.10")
metrics.togglePause(); mark("resumed")
}
controller.hide()
await wait(1); mark("closed\(cycle).1")
await wait(9); mark("closed\(cycle).10")
await wait(20); mark("closed\(cycle).30")
}
controller.shutdown()
mark("complete")
NSApp.terminate(nil)
}
}
}
+1
View File
@@ -17,6 +17,7 @@ struct ProcessIcon: View {
.frame(width: 15, height: 15)
.accessibilityHidden(true)
.task(id: "\(process.id)-\(process.path ?? "")") {
guard PanelResourceAudit.omitted != "icons" else { return }
// Resolve by the sampled executable, avoiding an icon from a reused PID.
guard let path = process.path else { icon = nil; return }
let url = URL(fileURLWithPath: path)