Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .memory/perf-ios-streaming.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# iOS streaming performance (EXT-9..21)

Branch `perf/ios-streaming`. iOS-only; no Remote protocol, fixture, or persisted-format change. Behavioral coverage lives in `ios/AidenOnTheGoTests/AidenStreamingPerformanceTests.swift` plus focused additions in `AidenChatTests` and `AidenRemoteClientTests`.

- EXT-9: `AidenLatestValueThrottle` (LiveActivities/) coalesces Live Activity content to the newest value at most once per second. Status, approval, stale, finish, and end paths are urgent and bypass or cancel the pending write.
- EXT-10: `AidenMarkdownContentCache` (Features/Remote/) splits Markdown only at safe blank-line block boundaries and caches parsed settled chunks in a bounded LRU (512 entries / 400k UTF-8 bytes). Only the open tail is reparsed. Splitting is disabled for link/footnote definitions and blank-line-spanning HTML. Oracle: for every prefix of the fixtures, the chunked result equals `MarkdownContent(prefix)`. `AidenLiveResponseView` evaluates its projections once per render.
- EXT-12/17: the chat open takes a single progress snapshot that observation reuses. Reconciliation backoff uses equal jitter (cap 30 s). Android has the same backoff shape in `AidenChat.kt`, left to the Android workstream.
- EXT-19: `AidenSSELineDecoder` (in AidenSSEParser.swift) checks cancellation and validates UTF-8 once per line. LF/CRLF handling, blank-line delimiters, EOF discard, and the frame limit are unchanged. Do not use `bytes.lines`, because it drops blank lines.
- EXT-13: `activeClient()` returns the cached client before reading the Keychain. The key covers instance, device, credential scope, and activation generation.
- EXT-14/16: interactive calls use a 5-minute resource budget. SSE streams use a separate session (1 h resource, 30 s idle = two missed 15 s heartbeats). Clients `finishTasksAndInvalidate` the sessions they own in `deinit`; injected test sessions are never invalidated.
- EXT-11: `AidenSceneRefreshGate` refetches only on `.active` after `.background`. ContentView and the chat detail ignore transient `.inactive` bounces. The chat load is keyed by an epoch, so a newer load cancels an older one. No conditional fetch, because that needs a protocol change.
- EXT-18: ThinkingOrb is capped at 30 fps. The orb and the shimmers hold still under the `aidenLowPowerMode` environment, which `AidenAppearanceRoot` injects.
- Deferred EXT-15: `AidenChatCache.admittedChats` is the in-memory winner for failed disk writes and list merges. Bounding it needs a design for committed-only eviction plus disk fallback. Summary writes happen once per `saveChat` (on load or send, not per token), so a debounce would gain little.
- Skipped EXT-21: the settled-rows child's `ForEach` flattens into the parent `LazyVStack` (custom views and `EquatableView` are transparent to list flattening), so rows stay lazy. Not profiled in Instruments.
- EXT-20: no broad file split. Only the new types were extracted into their own files.
16 changes: 16 additions & 0 deletions ios/AidenOnTheGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
A0D700000000000000000002 /* AidenSSEParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0D700000000000000000012 /* AidenSSEParser.swift */; };
A0D700000000000000000003 /* AidenChatCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0D700000000000000000013 /* AidenChatCache.swift */; };
A0D700000000000000000004 /* AidenChatFeature.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0D700000000000000000014 /* AidenChatFeature.swift */; };
A0F100000000000000000041 /* AidenSceneRefreshGate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0F100000000000000000040 /* AidenSceneRefreshGate.swift */; };
A0F100000000000000000031 /* AidenMarkdownContentCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0F100000000000000000030 /* AidenMarkdownContentCache.swift */; };
A0D700000000000000000005 /* AidenChatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0D700000000000000000015 /* AidenChatTests.swift */; };
A0F100000000000000000021 /* AidenStreamingPerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0F100000000000000000020 /* AidenStreamingPerformanceTests.swift */; };
A0D800000000000000000001 /* AidenAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0D800000000000000000011 /* AidenAppearance.swift */; };
A0D800000000000000000004 /* AidenChromeGlass.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0D800000000000000000014 /* AidenChromeGlass.swift */; };
A0D800000000000000000003 /* AidenVoiceInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0D800000000000000000013 /* AidenVoiceInput.swift */; };
Expand Down Expand Up @@ -57,6 +60,7 @@
A04500000000000000000007 /* AidenLiveActivityWidget.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = A04500000000000000000017 /* AidenLiveActivityWidget.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
A04500000000000000000008 /* aiden-sidebar-logo.png in Resources */ = {isa = PBXBuildFile; fileRef = A04500000000000000000018 /* aiden-sidebar-logo.png */; };
A0DB00000000000000000001 /* AidenRemoteLiveActivityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0DB00000000000000000011 /* AidenRemoteLiveActivityManager.swift */; };
A0F100000000000000000011 /* AidenLatestValueThrottle.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0F100000000000000000010 /* AidenLatestValueThrottle.swift */; };
A0DB00000000000000000002 /* AidenNativeIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0DB00000000000000000012 /* AidenNativeIntegrationTests.swift */; };
B07200000000000000000001 /* AidenBotPrototypeSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B07200000000000000000011 /* AidenBotPrototypeSnapshotTests.swift */; };
B07300000000000000000001 /* AidenBot.swift in Sources */ = {isa = PBXBuildFile; fileRef = B07300000000000000000011 /* AidenBot.swift */; };
Expand Down Expand Up @@ -143,7 +147,10 @@
A0DC00000000000000000011 /* AidenChatProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AidenChatProgress.swift; sourceTree = "<group>"; };
A0D700000000000000000012 /* AidenSSEParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AidenSSEParser.swift; sourceTree = "<group>"; };
A0D700000000000000000013 /* AidenChatCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AidenChatCache.swift; sourceTree = "<group>"; };
A0F100000000000000000030 /* AidenMarkdownContentCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AidenMarkdownContentCache.swift; sourceTree = "<group>"; };
A0F100000000000000000040 /* AidenSceneRefreshGate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AidenSceneRefreshGate.swift; sourceTree = "<group>"; };
A0D700000000000000000014 /* AidenChatFeature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AidenChatFeature.swift; sourceTree = "<group>"; };
A0F100000000000000000020 /* AidenStreamingPerformanceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AidenStreamingPerformanceTests.swift; sourceTree = "<group>"; };
A0D700000000000000000015 /* AidenChatTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AidenChatTests.swift; sourceTree = "<group>"; };
A0D800000000000000000011 /* AidenAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AidenAppearance.swift; sourceTree = "<group>"; };
A0D800000000000000000013 /* AidenVoiceInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AidenVoiceInput.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -201,6 +208,7 @@
A04500000000000000000014 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A04500000000000000000018 /* aiden-sidebar-logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "aiden-sidebar-logo.png"; path = AidenOnTheGo/Resources/Assets.xcassets/AidenSidebarLogo.imageset/aiden-sidebar-logo.png; sourceTree = SOURCE_ROOT; };
A04500000000000000000017 /* AidenLiveActivityWidget.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = AidenLiveActivityWidget.appex; sourceTree = BUILT_PRODUCTS_DIR; };
A0F100000000000000000010 /* AidenLatestValueThrottle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AidenLatestValueThrottle.swift; sourceTree = "<group>"; };
A0DB00000000000000000011 /* AidenRemoteLiveActivityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AidenRemoteLiveActivityManager.swift; sourceTree = "<group>"; };
A0DB00000000000000000012 /* AidenNativeIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AidenNativeIntegrationTests.swift; sourceTree = "<group>"; };
B07200000000000000000011 /* AidenBotPrototypeSnapshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AidenBotPrototypeSnapshotTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -314,6 +322,7 @@
A0D000000000000000000013 /* AidenRemotePhase0Tests.swift */,
A0D600000000000000000013 /* AidenRemoteClientTests.swift */,
A0D700000000000000000015 /* AidenChatTests.swift */,
A0F100000000000000000020 /* AidenStreamingPerformanceTests.swift */,
A0D800000000000000000012 /* AidenAppearanceV1.json */,
A0D000000000000000000014 /* AidenRemoteContractV1.json */,
A0D000000000000000000015 /* AidenManualPairingVectorV1.json */,
Expand Down Expand Up @@ -404,6 +413,8 @@
A0D600000000000000000015 /* AidenPairingView.swift */,
A0D600000000000000000016 /* AidenWorkspaceShellView.swift */,
A0D700000000000000000014 /* AidenChatFeature.swift */,
A0F100000000000000000040 /* AidenSceneRefreshGate.swift */,
A0F100000000000000000030 /* AidenMarkdownContentCache.swift */,
);
path = Remote;
sourceTree = "<group>";
Expand Down Expand Up @@ -502,6 +513,7 @@
A04500000000000000000010 /* AgentRunActivityAttributes.swift */,
A04500000000000000000011 /* AidenDeepLink.swift */,
A0DB00000000000000000011 /* AidenRemoteLiveActivityManager.swift */,
A0F100000000000000000010 /* AidenLatestValueThrottle.swift */,
);
path = LiveActivities;
sourceTree = "<group>";
Expand Down Expand Up @@ -733,6 +745,7 @@
A04500000000000000000001 /* AgentRunActivityAttributes.swift in Sources */,
A04500000000000000000002 /* AidenDeepLink.swift in Sources */,
A0DB00000000000000000001 /* AidenRemoteLiveActivityManager.swift in Sources */,
A0F100000000000000000011 /* AidenLatestValueThrottle.swift in Sources */,
A710739233F64F4FA4C2B700 /* ComposerVoiceInputController.swift in Sources */,
A711739233F64F4FA4C2B700 /* AidenAttachmentPicker.swift in Sources */,
A712739233F64F4FA4C2B700 /* AidenAttachmentCamera.swift in Sources */,
Expand All @@ -755,6 +768,8 @@
A0D700000000000000000002 /* AidenSSEParser.swift in Sources */,
A0D700000000000000000003 /* AidenChatCache.swift in Sources */,
A0D700000000000000000004 /* AidenChatFeature.swift in Sources */,
A0F100000000000000000041 /* AidenSceneRefreshGate.swift in Sources */,
A0F100000000000000000031 /* AidenMarkdownContentCache.swift in Sources */,
A0D800000000000000000001 /* AidenAppearance.swift in Sources */,
A0D800000000000000000003 /* AidenVoiceInput.swift in Sources */,
A0D800000000000000000004 /* AidenChromeGlass.swift in Sources */,
Expand All @@ -781,6 +796,7 @@
A0D000000000000000000003 /* AidenRemotePhase0Tests.swift in Sources */,
A0D600000000000000000003 /* AidenRemoteClientTests.swift in Sources */,
A0D700000000000000000005 /* AidenChatTests.swift in Sources */,
A0F100000000000000000021 /* AidenStreamingPerformanceTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
15 changes: 15 additions & 0 deletions ios/AidenOnTheGo/Config/AidenAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ private struct AidenPaletteEnvironmentKey: EnvironmentKey {
}

private struct AidenReduceMotionEnvironmentKey: EnvironmentKey { static let defaultValue = false }
private struct AidenLowPowerModeEnvironmentKey: EnvironmentKey { static let defaultValue = false }
private struct AidenDiffMarkerEnvironmentKey: EnvironmentKey { static let defaultValue = AidenDiffMarkerPreference.symbols }
private struct AidenSidebarTranslucencyEnvironmentKey: EnvironmentKey { static let defaultValue = true }
private struct AidenCodeTypographyEnvironmentKey: EnvironmentKey {
Expand All @@ -479,6 +480,13 @@ extension EnvironmentValues {
set { self[AidenReduceMotionEnvironmentKey.self] = newValue }
}

/// True while the system Low Power Mode is on. Decorative, continuously
/// redrawn animations (orbs, shimmers) hold still to save power.
var aidenLowPowerMode: Bool {
get { self[AidenLowPowerModeEnvironmentKey.self] }
set { self[AidenLowPowerModeEnvironmentKey.self] = newValue }
}

var aidenDiffMarkers: AidenDiffMarkerPreference {
get { self[AidenDiffMarkerEnvironmentKey.self] }
set { self[AidenDiffMarkerEnvironmentKey.self] = newValue }
Expand All @@ -500,6 +508,7 @@ struct AidenAppearanceRoot<Content: View>: View {
@Environment(\.colorScheme) private var colorScheme
@Environment(\.colorSchemeContrast) private var colorSchemeContrast
@Environment(\.accessibilityReduceMotion) private var systemReduceMotion
@State private var lowPowerMode = ProcessInfo.processInfo.isLowPowerModeEnabled
@ViewBuilder let content: () -> Content

var body: some View {
Expand All @@ -515,13 +524,19 @@ struct AidenAppearanceRoot<Content: View>: View {
content()
.environment(\.aidenPalette, palette)
.environment(\.aidenReduceMotion, appearance.resolvedReduceMotion(system: systemReduceMotion))
.environment(\.aidenLowPowerMode, lowPowerMode)
.environment(\.aidenDiffMarkers, appearance.diffMarkers)
.environment(\.aidenSidebarTranslucent, appearance.translucentSidebar(for: effectiveScheme))
.environment(\.aidenCodeTypography, AidenCodeTypography(font: appearance.codeFont(for: effectiveScheme), size: appearance.codeFontSize))
.modifier(AidenUITypographyModifier(font: appearance.uiFont(for: effectiveScheme), size: appearance.uiFontSize))
.preferredColorScheme(appearance.mode.colorScheme)
.tint(palette.accent)
.background(palette.canvas.ignoresSafeArea())
.task {
for await _ in NotificationCenter.default.notifications(named: .NSProcessInfoPowerStateDidChange) {
lowPowerMode = ProcessInfo.processInfo.isLowPowerModeEnabled
}
}
}
}

Expand Down
11 changes: 7 additions & 4 deletions ios/AidenOnTheGo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct ContentView: View {
@Environment(\.scenePhase) private var scenePhase
@AppStorage("aiden.mobileOnboarding.v1.complete") private var hasCompletedMobileOnboarding = false
@State private var navigationRequest: AidenNavigationRequest?
@State private var sceneRefreshGate = AidenSceneRefreshGate(refreshOnFirstActivation: true)

var body: some View {
Group {
Expand Down Expand Up @@ -33,8 +34,8 @@ struct ContentView: View {
Task { await open(request) }
}
.onChange(of: scenePhase) { _, phase in
switch phase {
case .active:
switch sceneRefreshGate.transition(to: phase) {
case .refresh:
guard coordinator.connectionState != .needsPairing else { return }
Task {
await coordinator.connectActiveInstallation()
Expand All @@ -47,9 +48,11 @@ struct ContentView: View {
)
}
}
case .background:
case .suspend:
Task { await AidenRemoteLiveActivityManager.shared.markAllStale() }
default:
case .resume, .none:
// Returning from a transient `.inactive` (Control Center,
// app switcher, system prompts) keeps the live connection.
break
}
}
Expand Down
3 changes: 2 additions & 1 deletion ios/AidenOnTheGo/Features/Bots/AidenBotsHomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ private struct AidenBotHomeSkeletonView: View {

struct AidenBotSkeletonBlock: View {
@Environment(\.aidenPalette) private var palette
@Environment(\.aidenLowPowerMode) private var lowPowerMode
let width: CGFloat?
let height: CGFloat
let radius: CGFloat
Expand All @@ -247,7 +248,7 @@ struct AidenBotSkeletonBlock: View {
RoundedRectangle(cornerRadius: radius, style: .continuous)
.fill(palette.raised)
.overlay {
if !reduceMotion {
if !reduceMotion && !lowPowerMode {
TimelineView(.animation(minimumInterval: 1.0 / 30.0)) { timeline in
let duration = 1.6
let elapsed = timeline.date.timeIntervalSinceReferenceDate
Expand Down
Loading
Loading