Skip to content

App Performance + Diagnostic Report#774

Merged
CodeWithCJ merged 10 commits intoCodeWithCJ:mainfrom
apedley:app-perf
Feb 27, 2026
Merged

App Performance + Diagnostic Report#774
CodeWithCJ merged 10 commits intoCodeWithCJ:mainfrom
apedley:app-perf

Conversation

@apedley
Copy link
Contributor

@apedley apedley commented Feb 27, 2026

Description

Added diagnostic report feature where uses can generate a report. Note that all health and other personal data has been removed from logs so there is zero chance it could accidentally get sent in the report. The only information in the report is about the device, if it's connected, and the kind of errors that have been happening. Once this change is up on the App Store, I plan on adding a section to the docs for this with instructions and an example report.

Significantly increased performance of some modules, such as Log Service.
Optimized react query for fewer fetches
Animation improvements

Related Issue

PR type [ ] Issue [ ] New Feature [ ] Documentation
Linked Issue: #

Checklist

Please check all that apply:

  • Alignment: I have raised a GitHub issue and it was reviewed/approved by maintainers (required for new features).
  • Tests: I have included automated tests for my changes.
  • Screenshots: I have attached "Before" vs "After" screenshots below (required for UI changes).
  • Quality: I have run npm run lint and npm run format (especially for Frontend).
  • Translations: I have only updated the English (en) translation file (if applicable).
  • Architecture: My code follows the existing architecture standards.
  • Database Security: I have updated rls_policies.sql for any new user-specific tables.
  • Integrity: I certify this is my own work, free of malicious code(phishing, malware, etc.)
  • License: I agree to the License terms.

Screenshots (if applicable)

Before

[Insert screenshot/GIF here]

After

[Insert screenshot/GIF here]

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new diagnostic reporting capability to assist with debugging and support, while also delivering substantial performance enhancements across several core modules. Key areas of improvement include the Log Service, React Query data fetching, and UI animations, all contributing to a more responsive and efficient user experience.

Highlights

  • Diagnostic Report Feature: Introduced a new feature allowing users to generate and share a diagnostic report from the Settings screen. This report includes sanitized app, device, sync, and log information, along with React Query states, to aid in troubleshooting without exposing sensitive personal health or food data.
  • Log Service Performance & Reliability: Implemented a write-buffering mechanism for the Log Service, significantly improving performance by reducing frequent AsyncStorage writes. Logs are now flushed periodically, when a threshold is met, or when the app enters the background. A cache for the log filter was also added, and console.error calls were replaced with addLog for centralized logging.
  • React Query Optimization: Enhanced the useRefetchOnFocus hook to include a staleTime parameter, preventing redundant network requests when rapidly switching between screens. The useDailySummary hook was refactored to separate raw data fetching from derived data selection, improving data consistency and reducing re-renders.
  • Animation Performance Improvements: Optimized Skia rendering in ExerciseProgressCard, MacroCard, and ProgressRing components by replacing Path objects with Rect objects or memoizing oval calculations where appropriate, leading to smoother animations.
  • Storage Caching for Server Configuration: Implemented a caching mechanism for getActiveServerConfig to reduce repeated reads from AsyncStorage and SecureStore, improving the responsiveness of server-related operations.
Changelog
  • SparkyFitnessMobile/App.tsx
    • Initialized the LogService at app startup to warm its cache and register an AppState listener.
  • SparkyFitnessMobile/tests/hooks/useRefetchOnFocus.test.ts
    • Added new test cases to verify the staleTime functionality of the useRefetchOnFocus hook, ensuring refetches are skipped within the configured stale period.
  • SparkyFitnessMobile/tests/hooks/useWaterIntakeMutation.test.ts
    • Updated tests to reflect the new DailySummaryRawData type, ensuring optimistic updates correctly modify the waterIntake.water_ml property.
  • SparkyFitnessMobile/tests/services/LogService.test.ts
    • Added comprehensive tests for log buffering, flushing logic, and log filter caching, including scenarios for buffer thresholds, in-flight flushes, and error handling.
  • SparkyFitnessMobile/tests/services/diagnosticReportService.test.ts
    • Added new test file for the diagnostic report service, covering collection of app info, device info, sync status, log info, health metrics, theme, report building, and sharing functionality, including data sanitization.
  • SparkyFitnessMobile/tests/services/storage.test.ts
    • Added tests for the getActiveServerConfig caching mechanism, verifying cache hits, invalidation on config changes, and error handling.
  • SparkyFitnessMobile/jest.setup.js
    • Added mocks for expo-device, expo-file-system, and expo-sharing to support testing of the diagnostic report feature.
  • SparkyFitnessMobile/package-lock.json
    • Updated package-lock.json to include new dependencies for expo-device, expo-file-system, and expo-sharing.
  • SparkyFitnessMobile/package.json
    • Added expo-device, expo-file-system, and expo-sharing as new dependencies.
  • SparkyFitnessMobile/src/components/ExerciseProgressCard.tsx
    • Optimized Skia rendering by replacing Path objects with Rect objects for progress bars, improving animation performance.
  • SparkyFitnessMobile/src/components/Icon.tsx
    • Added a new 'share' icon to the ICON_MAP for use in the diagnostic report feature.
  • SparkyFitnessMobile/src/components/MacroCard.tsx
    • Optimized Skia rendering by replacing Path objects with Rect objects for macro progress bars, enhancing animation smoothness.
  • SparkyFitnessMobile/src/components/ProgressRing.tsx
    • Optimized Skia rendering by memoizing the oval calculation for the progress ring, reducing re-renders.
  • SparkyFitnessMobile/src/hooks/useDailySummary.ts
    • Refactored the useDailySummary hook to introduce DailySummaryRawData for raw data fetching and use the select option for transforming data into DailySummary, improving data flow and reducing re-renders.
    • Imported new types DailyGoals, FoodEntry, ExerciseEntry, and WaterIntake.
  • SparkyFitnessMobile/src/hooks/useRefetchOnFocus.ts
    • Implemented a staleTime parameter to the useRefetchOnFocus hook, preventing refetches if the screen is re-focused within the specified time period.
  • SparkyFitnessMobile/src/hooks/useWaterIntakeMutation.ts
    • Updated optimistic update logic to use DailySummaryRawData type, ensuring correct modification of waterIntake.water_ml.
  • SparkyFitnessMobile/src/screens/SettingsScreen.tsx
    • Integrated the 'Share Diagnostic Report' button and functionality, allowing users to generate and share a sanitized report.
    • Imported usePreferences and queryClient to collect user preferences and query states for the diagnostic report.
    • Added ActivityIndicator for the sharing process.
  • SparkyFitnessMobile/src/screens/SyncScreen.tsx
    • Removed redundant fetchHealthData calls from useEffect and onSelect for time range, as background sync handles data fetching.
  • SparkyFitnessMobile/src/services/LogService.ts
    • Implemented log write buffering with a flush interval and threshold, significantly reducing AsyncStorage writes.
    • Added an AppState listener to flush logs when the app goes into the background.
    • Introduced caching for the log filter (cachedFilter) to avoid repeated AsyncStorage reads.
    • Added _resetForTesting and _flushBuffer exports for explicit test control.
    • Removed console.error calls, directing all errors through addLog for centralized logging.
  • SparkyFitnessMobile/src/services/api/healthDataApi.ts
    • Removed direct console.error calls, ensuring all API-related errors are logged via addLog.
  • SparkyFitnessMobile/src/services/diagnosticReportService.ts
    • Added new service file to collect, sanitize, build, and share diagnostic reports.
    • Implemented functions to collect app info, device info, sync status, log info, enabled health metrics, and theme.
    • Included sanitization logic for log entries, query keys, and user preferences to protect sensitive data.
  • SparkyFitnessMobile/src/services/healthconnect/dataAggregation.ts
    • Simplified log messages for health data aggregation functions, removing verbose JSON stringification.
  • SparkyFitnessMobile/src/services/healthconnect/dataTransformation.ts
    • Simplified log messages for health data transformation functions, removing verbose value logging and improving error messages.
  • SparkyFitnessMobile/src/services/healthconnect/index.ts
    • Removed direct console.error calls, ensuring all Health Connect service errors are logged via addLog.
  • SparkyFitnessMobile/src/services/storage.ts
    • Implemented caching for getActiveServerConfig to improve performance by reducing storage access.
    • Added clearServerConfigCache function to invalidate the cache, primarily for testing purposes.
    • Ensured cache invalidation on saveServerConfig, setActiveServerConfig, and deleteServerConfig.
  • SparkyFitnessMobile/src/types/diagnosticReport.ts
    • Added new type definitions for DiagnosticQueryState, DiagnosticHookData, DiagnosticReportMetadata, DiagnosticAppInfo, DiagnosticDeviceInfo, DiagnosticSyncStatus, DiagnosticLogInfo, and DiagnosticReport.
Activity
  • The author, apedley, completed the following checklist items:
    • Automated tests were included for the changes.
    • npm run lint and npm run format were run.
    • The code follows existing architecture standards.
    • The author certifies this is their own work, free of malicious code.
    • The author agrees to the License terms.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a valuable diagnostic report feature and delivers significant performance enhancements across the application. The new logging service with write-buffering, caching for server configurations, and optimizations in React Query hooks and Skia components are all excellent improvements. The implementation is robust, well-tested, and demonstrates a strong consideration for user privacy through data sanitization in logs and reports. I have one minor suggestion to improve the clarity of a log message for easier debugging.

@CodeWithCJ CodeWithCJ merged commit 6869980 into CodeWithCJ:main Feb 27, 2026
6 checks passed
@apedley apedley deleted the app-perf branch February 27, 2026 21:58
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.

2 participants