Performance optimizations: formatter caching, view extraction, query limits#1763
Merged
Conversation
…limits - CoTMessage: Make ISO8601DateFormatter a static let instead of creating per toXML() call - DiscoveryScanEngine: Add CustomStringConvertible to DiscoveryScanState, remove String(describing:) wrapper from log interpolations - CarPlaySceneDelegate: Move favorite filter into #Predicate and add fetchLimit: 50 to avoid loading all nodes - RateLimitedButton: Move objectWillChange.send() after cleanup check to avoid unnecessary view redraws after timer stops - NodeDetail: Extract 600-line body into 6 @ViewBuilder section properties for granular SwiftUI diffing
Remove Tips.MaxDisplayCount(3) from ConnectionTip. The tip uses PersistentTipStyle which has no dismiss button, so it should always appear when connected. The max count caused TipKit to internally invalidate the tip after 3 views, rendering it invisible.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR applies several targeted performance optimizations across TAK XML generation, discovery logging, CarPlay SwiftData fetching, and the Node Detail SwiftUI view composition.
Changes:
- Reduced repeated work by caching/avoiding expensive formatting & reflection (
CoTMessagedate formatter caching;DiscoveryScanStateCustomStringConvertiblefor logging). - Improved data/UI efficiency by moving filtering into SwiftData predicates and extracting
NodeDetail’s largebodyinto section subviews. - Minor behavioral/refresh adjustments (rate-limit timer
objectWillChangeordering; TipKit options changed forConnectionTip).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| Meshtastic/Views/Nodes/Helpers/NodeDetail.swift | Extracts the large Node Detail body into section subviews; keeps feature parity while aiming to reduce SwiftUI recomputation. |
| Meshtastic/Views/Helpers/RateLimitedButton.swift | Reorders timer tick publishing logic intended to reduce unnecessary UI updates. |
| Meshtastic/Tips/BluetoothTips.swift | Changes ConnectionTip display options (removes max display count). |
| Meshtastic/Services/DiscoveryScanEngine.swift | Adds CustomStringConvertible to DiscoveryScanState and uses it in log messages to avoid reflection. |
| Meshtastic/Helpers/TAK/CoTMessage.swift | Caches an ISO8601DateFormatter for toXML() generation to reduce per-call allocation. |
| Meshtastic/CarPlay/CarPlaySceneDelegate.swift | Moves favorites filtering into a SwiftData predicate and adds a fetch limit for performance. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/0867e03f-148b-4ec7-9e09-2162d76419b5 Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a031fb01-f381-413c-a593-5333638d7774 Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a031fb01-f381-413c-a593-5333638d7774 Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Five performance optimizations from a codebase audit:
1. Static DateFormatter in CoTMessage (trivial)
ISO8601DateFormatterwas instantiated on everytoXML()call. Now astatic let— reused across all instances.2. CustomStringConvertible for DiscoveryScanState (trivial)
Removed
String(describing:)reflection calls from log interpolations. AddedCustomStringConvertibleconformance with direct string returns.3. Predicate-based favorite filter in CarPlay (easy)
fetchFavoriteContactItems()was loading ALLNodeInfoEntityrecords then filtering to favorites in memory. Moved thefavorite == truefilter into the#Predicateand addedfetchLimit: 50.4. Timer objectWillChange ordering in RateLimitedButton (easy)
objectWillChange.send()was called unconditionally at the top of each 1-second timer tick, even after all rate limits expired. Moved it after the cleanup check so the final tick doesn't trigger an unnecessary view redraw.5. NodeDetail view body extraction (medium)
600+ line monolithic
bodyproperty split into 6@ViewBuildersection properties:nodeSection,environmentSection,powerSection,logsSection,actionsSection,administrationSection. Enables granular SwiftUI diffing — changes to one section no longer force recomputation of the entire hierarchy.How it was tested