Skip to content

Optimize iOS launch, rendering, sync, Ask AI, and data hot paths - #452

Open
luworks wants to merge 5 commits into
mainfrom
t3/ios-speed-improvements
Open

luworks wants to merge 5 commits into
mainfrom
t3/ios-speed-improvements

Conversation

@luworks

@luworks luworks commented Dec 6, 2026

Copy link
Copy Markdown
Owner

Comprehensive end-to-end iOS performance optimization across launch, shell, Today/Calendar rendering, Ask/AI chat, Reminders/Search/Clock/Health/Activity/Settings, sync, SQLite storage, and shared UI primitives:

Launch, Shell & Navigation

  • Defer cities.json disk read/JSON decode/ICU folding out of OneApp.init() via async WorldClockStore(citiesURL:...) with fast home-zone fallback.
  • Move BackupController.discover() and BackupController.save() off @MainActor, eliminate redundant archive re-validation, and stop triggering backups on foreground/non-change activity flushes.
  • Isolate session.calendar.version, AskOverlayModel, and drawer.isOpen out of HomeView.body so calendar bumps, Chat open/close, and drawer slides never invalidate the entire shell.
  • Deduplicate cold-launch bootstrap() vs initial scenePhase == .active, offload outbox import and daily-gated ActivityStore.prune, and eliminate the 250ms pre-build race before prepareNewAsk().
  • Hoist YearMarksCache and MonthMarksCache on HomeView so lens switches preserve computed calendar caches; defer ChatAutoArchive.run past the sidebar open spring and short-circuit idle thresholds before N+1 queries.
  • Eliminate the permanent full-screen offscreen .mask render pass in DrawerMainSlide when closed (p == 0) using a Shape clip.

Today, Calendar & Shared UI Rows

  • Year: Per-year @Observable YearSlot, cached YearLayout.blank, static 4×3 grid, Equatable MiniMonth, gated .accessibilityChildren, precomputed day IDs, and Text(verbatim:) in Canvas.
  • Week: Single-window CalendarEntries.make bucketed into Equatable DayColumns, Canvas hour lines, isolated WeekNowLine/WeekNowLabel minute TimelineView (removing 60s full-grid timer), cached secondCity and 24 hour labels, and scroll-isolated AllDayRow.
  • Month: Remove inline 30s Timer.publish (sleep until next midnight/one-off alarm), per-month MonthSlot, lazy folded MonthFold pager, coalesced AgendaRowTracking, detached MonthAgendaList.load(), and O(days + entries) MonthSummary.summarize.
  • Day: Batched ActivityCenter.observePlans with in-memory dedup cache, async off-@MainActor DayHistory.loadAsync + O(N) reconstruct, O(1) TodayFocus settled index & memoized reference(_:).
  • Shared formatters & rows: Cache DateFormatters in TimeColumn, PlannerConsumerTime, TravelTimes, MonthLabel, AlarmPlan.timeParts, plannerDayLabel, and QuickTime; cache CalendarTimeZone.city(stored:); hoist duplicate per-row locals in TaskRow/EventRow/ExternalEventRow; replace ViewThatFits in TitleDetail with a single-tree Layout.

Ask / AI Chat & Core Parsers

  • Add lock-backed RegexCache across all TodayCore parsers & AgentPlannerTools.fold with ASCII fast paths.
  • Remove top-level @Querys from permanently-mounted AskView, isolate AskComposerState (draft/quick) from conversation rendering, gate DraftMatchesHost on >= minimumLength, avoid unnecessary withAnimation on unchanged quick drafts, and batch per-turn SwiftData saves.
  • Make FastLane.looksLikeEdit / localPreview lazily evaluate editItems(), optimize JSONValue.parse & LunaStreamDecoder (zero thrown DecodingErrors on ignored deltas), add zero-allocation JSONValue.utf8ByteCount and O(1) AgentHistory.shortID, and cache AIService.credentials in memory.

Reminders, Search, Clock, Health, Activity, Settings, Sync & SQLite

  • Reminders / Search / Clock / Health / Activity / Settings: Single-pass RemindersStats, #Predicate list queries, lazy SearchResultsHost @Querys with match-before-EventKit-filter, cached WorldClockStore.home/others, conditional AlarmsSectionView @Querys, 120Hz TimeWheelPicker caches, single-pass HealthMetricDetail snapshot + O(D+N) sliding MovingAverage + bounded reverse HealthSpark.slots, off-@MainActor ActivityView/ActivityDataView SQLite queries, and dark-mode single-render / isolated section @AppStorage in SettingsView.
  • Sync & Data: Debounce .EKEventStoreChanged, superset-interval cache hits in CalendarSync, entity-filtered ModelContext.didSave + concurrent fetchRemote() + background >30d probe in RemindersSync, O(1) calendar fast-forward in Recurrence.occurrences + nextOccurrence, diffed Reminders.resync(), off-main AlarmManager.shared.alarms, coalesced off-main WidgetFeed + 2-day cached butlerDay(), #Predicate single-record fetches, ActivityStore Migration 3 composite indexes + PRAGMAs + prepared statement cache + batched events(forSubjectRefs:), and off-main periodic ActivityRecorder flushes.
  • Tests: Added SpeedOptimizationTests covering recurrence fast-forward/DST parity, JSONValue/LunaStreamDecoder, AgentHistory.shortID, lazy FastLane, SearchMatch, RegexCache, ActivityStore batched queries, and TodayFocusStore indexing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant