react-native-inapp-inspector 2.3.18 → 2.3.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/inappinspector/NetworkInspectorModule.kt +57 -0
- package/dist/commonjs/analytics.js +1 -24
- package/dist/commonjs/bundle.js +1 -16
- package/dist/commonjs/capture.d.ts +2 -0
- package/dist/commonjs/capture.js +1 -32
- package/dist/commonjs/components/AnalyticsDetail.js +92 -623
- package/dist/commonjs/components/AnalyticsEventCard.js +54 -350
- package/dist/commonjs/components/AnalyticsGraph.js +70 -370
- package/dist/commonjs/components/AnimatedEntrance.js +1 -11
- package/dist/commonjs/components/AppHeaderLogo.js +7 -134
- package/dist/commonjs/components/BrandCircleIcon.js +73 -118
- package/dist/commonjs/components/BrandSquareIcon.js +63 -108
- package/dist/commonjs/components/CodeSnippet.js +48 -623
- package/dist/commonjs/components/ConsoleLogCard.js +63 -537
- package/dist/commonjs/components/CopyButton.js +3 -89
- package/dist/commonjs/components/DiffViewer.js +19 -83
- package/dist/commonjs/components/DomainHeader.js +27 -127
- package/dist/commonjs/components/EmptyState.d.ts +1 -0
- package/dist/commonjs/components/EmptyState.js +10 -87
- package/dist/commonjs/components/EndOfListFooter.js +7 -81
- package/dist/commonjs/components/ErrorBoundary.js +72 -566
- package/dist/commonjs/components/HeadersSection.js +31 -110
- package/dist/commonjs/components/HighlightText.js +17 -58
- package/dist/commonjs/components/Inspector/AboutModal.d.ts +6 -0
- package/dist/commonjs/components/Inspector/AboutModal.js +351 -0
- package/dist/commonjs/components/Inspector/AnalyticsFilterModal.js +98 -797
- package/dist/commonjs/components/Inspector/AnalyticsTab.js +284 -930
- package/dist/commonjs/components/Inspector/BundleTab.js +551 -2918
- package/dist/commonjs/components/Inspector/ConsoleTab.js +79 -492
- package/dist/commonjs/components/Inspector/CrashDetail.js +123 -672
- package/dist/commonjs/components/Inspector/CrashFilterModal.js +66 -498
- package/dist/commonjs/components/Inspector/CrashTab.js +98 -670
- package/dist/commonjs/components/Inspector/DebuggingTab.js +64 -871
- package/dist/commonjs/components/Inspector/DeviceInfoTab.js +143 -907
- package/dist/commonjs/components/Inspector/FabLauncher.js +85 -54
- package/dist/commonjs/components/Inspector/FeatureUnderDevNotice.js +6 -99
- package/dist/commonjs/components/Inspector/FeedbackModal.d.ts +9 -0
- package/dist/commonjs/components/Inspector/FeedbackModal.js +167 -521
- package/dist/commonjs/components/Inspector/InspectorContext.js +1 -21
- package/dist/commonjs/components/Inspector/InspectorHeader.js +219 -1093
- package/dist/commonjs/components/Inspector/LogDetail.js +168 -994
- package/dist/commonjs/components/Inspector/MainScreen.js +60 -332
- package/dist/commonjs/components/Inspector/MediaGalleryTab.js +136 -278
- package/dist/commonjs/components/Inspector/MediaPreviewModal.js +134 -361
- package/dist/commonjs/components/Inspector/NavigationTracker.js +1 -12
- package/dist/commonjs/components/Inspector/NetworkDetail.js +96 -432
- package/dist/commonjs/components/Inspector/NetworkFilterModal.js +60 -576
- package/dist/commonjs/components/Inspector/NetworkTab.js +84 -514
- package/dist/commonjs/components/Inspector/NpmStarPrompt.js +17 -433
- package/dist/commonjs/components/Inspector/NpmUpdateToast.js +25 -298
- package/dist/commonjs/components/Inspector/PerformanceTab.js +182 -1397
- package/dist/commonjs/components/Inspector/ReduxDetail.js +188 -1089
- package/dist/commonjs/components/Inspector/ReduxTab.js +85 -701
- package/dist/commonjs/components/Inspector/SettingsPanel.js +431 -3431
- package/dist/commonjs/components/Inspector/SkeletonPlaceholder.js +11 -180
- package/dist/commonjs/components/Inspector/StorageTab.js +93 -826
- package/dist/commonjs/components/Inspector/TabBar.js +47 -183
- package/dist/commonjs/components/Inspector/UpdateAvailableModal.js +34 -408
- package/dist/commonjs/components/JsonViewer.js +168 -380
- package/dist/commonjs/components/LogCard.js +57 -567
- package/dist/commonjs/components/LogSyntaxHighlighter.js +11 -130
- package/dist/commonjs/components/MetaAccordion.js +69 -238
- package/dist/commonjs/components/MiniBarChart.js +3 -56
- package/dist/commonjs/components/MiniLineChart.js +3 -58
- package/dist/commonjs/components/NetworkIcons.d.ts +7 -0
- package/dist/commonjs/components/NetworkIcons.js +479 -997
- package/dist/commonjs/components/QRCodeView.js +5 -79
- package/dist/commonjs/components/SectionHeader.js +15 -37
- package/dist/commonjs/components/SegmentedTabs.js +7 -61
- package/dist/commonjs/components/SkeletonPlaceholder.js +11 -180
- package/dist/commonjs/components/Slider.js +15 -243
- package/dist/commonjs/components/SourcePageCard.js +30 -89
- package/dist/commonjs/components/Toast.js +5 -147
- package/dist/commonjs/components/TouchableScale.js +3 -24
- package/dist/commonjs/components/TreeNode.js +55 -130
- package/dist/commonjs/console.js +1 -16
- package/dist/commonjs/constants/index.js +1 -32
- package/dist/commonjs/constants/telemetryConfig.js +1 -6
- package/dist/commonjs/constants/version.d.ts +1 -1
- package/dist/commonjs/constants/version.js +1 -4
- package/dist/commonjs/crash.js +1 -23
- package/dist/commonjs/customHooks/analyticsLogger.js +1 -250
- package/dist/commonjs/customHooks/bundleAnalyzer.js +1 -957
- package/dist/commonjs/customHooks/consoleLogger.js +6 -445
- package/dist/commonjs/customHooks/crashHandler.js +7 -656
- package/dist/commonjs/customHooks/logFilters.js +1 -23
- package/dist/commonjs/customHooks/networkLogger.js +2 -536
- package/dist/commonjs/customHooks/performanceTracker.js +63 -750
- package/dist/commonjs/customHooks/reduxLogger.js +2 -313
- package/dist/commonjs/customHooks/storageInspector.js +1 -435
- package/dist/commonjs/customHooks/useAccordion.js +1 -18
- package/dist/commonjs/decorators/index.js +1 -100
- package/dist/commonjs/helpers/gaAnalyticsRegistry.js +1 -148
- package/dist/commonjs/helpers/index.js +8 -921
- package/dist/commonjs/helpers/memoryManager.js +1 -99
- package/dist/commonjs/helpers/qrGenerator.js +1 -367
- package/dist/commonjs/helpers/remoteConfig.js +1 -165
- package/dist/commonjs/helpers/searchQueryParser.js +1 -62
- package/dist/commonjs/helpers/settingsStore.js +1 -144
- package/dist/commonjs/helpers/telemetry.js +1 -501
- package/dist/commonjs/helpers/toast.js +1 -20
- package/dist/commonjs/i18n/index.js +1 -90
- package/dist/commonjs/i18n/locales/en.json +1 -1122
- package/dist/commonjs/index.js +5 -2153
- package/dist/commonjs/metro.js +6 -468
- package/dist/commonjs/native/NativeInspector.d.ts +3 -0
- package/dist/commonjs/native/NativeInspector.js +1 -402
- package/dist/commonjs/native/NativeNetworkInspector.d.ts +1 -0
- package/dist/commonjs/native/NativeNetworkInspector.js +1 -4
- package/dist/commonjs/network.js +1 -13
- package/dist/commonjs/performance.js +1 -29
- package/dist/commonjs/redux.js +1 -20
- package/dist/commonjs/storage.js +1 -14
- package/dist/commonjs/styles/AppColors.js +1 -423
- package/dist/commonjs/styles/AppFonts.js +1 -17
- package/dist/commonjs/styles/common.js +1 -190
- package/dist/commonjs/styles/index.d.ts +6 -0
- package/dist/commonjs/styles/index.js +1 -1589
- package/dist/commonjs/types/enums.d.ts +2 -1
- package/dist/commonjs/types/enums.js +1 -150
- package/dist/commonjs/types/index.js +1 -18
- package/dist/commonjs/types/interfaces.d.ts +7 -0
- package/dist/commonjs/types/interfaces.js +1 -2
- package/dist/esm/analytics.js +1 -2
- package/dist/esm/bundle.js +1 -2
- package/dist/esm/capture.d.ts +2 -0
- package/dist/esm/capture.js +1 -29
- package/dist/esm/components/AnalyticsDetail.js +171 -664
- package/dist/esm/components/AnalyticsEventCard.js +77 -335
- package/dist/esm/components/AnalyticsGraph.js +95 -357
- package/dist/esm/components/AnimatedEntrance.js +1 -6
- package/dist/esm/components/AppHeaderLogo.js +7 -94
- package/dist/esm/components/BrandCircleIcon.js +114 -119
- package/dist/esm/components/BrandSquareIcon.js +73 -78
- package/dist/esm/components/CodeSnippet.js +58 -595
- package/dist/esm/components/ConsoleLogCard.js +91 -526
- package/dist/esm/components/CopyButton.js +3 -51
- package/dist/esm/components/DiffViewer.js +22 -48
- package/dist/esm/components/DomainHeader.js +43 -138
- package/dist/esm/components/EmptyState.d.ts +1 -0
- package/dist/esm/components/EmptyState.js +17 -56
- package/dist/esm/components/EndOfListFooter.js +15 -83
- package/dist/esm/components/ErrorBoundary.js +125 -582
- package/dist/esm/components/HeadersSection.js +52 -93
- package/dist/esm/components/HighlightText.js +17 -53
- package/dist/esm/components/Inspector/AboutModal.d.ts +6 -0
- package/dist/esm/components/Inspector/AboutModal.js +351 -0
- package/dist/esm/components/Inspector/AnalyticsFilterModal.js +225 -886
- package/dist/esm/components/Inspector/AnalyticsTab.js +296 -904
- package/dist/esm/components/Inspector/BundleTab.js +1175 -3502
- package/dist/esm/components/Inspector/ConsoleTab.js +113 -488
- package/dist/esm/components/Inspector/CrashDetail.js +236 -747
- package/dist/esm/components/Inspector/CrashFilterModal.js +149 -541
- package/dist/esm/components/Inspector/CrashTab.js +177 -711
- package/dist/esm/components/Inspector/DebuggingTab.js +156 -923
- package/dist/esm/components/Inspector/DeviceInfoTab.js +199 -924
- package/dist/esm/components/Inspector/FabLauncher.js +85 -49
- package/dist/esm/components/Inspector/FeatureUnderDevNotice.js +14 -70
- package/dist/esm/components/Inspector/FeedbackModal.d.ts +9 -0
- package/dist/esm/components/Inspector/FeedbackModal.js +182 -499
- package/dist/esm/components/Inspector/InspectorContext.js +1 -12
- package/dist/esm/components/Inspector/InspectorHeader.js +309 -1145
- package/dist/esm/components/Inspector/LogDetail.js +235 -1023
- package/dist/esm/components/Inspector/MainScreen.js +86 -320
- package/dist/esm/components/Inspector/MediaGalleryTab.js +157 -259
- package/dist/esm/components/Inspector/MediaPreviewModal.js +153 -340
- package/dist/esm/components/Inspector/NavigationTracker.js +1 -10
- package/dist/esm/components/Inspector/NetworkDetail.js +141 -472
- package/dist/esm/components/Inspector/NetworkFilterModal.js +122 -597
- package/dist/esm/components/Inspector/NetworkTab.js +125 -517
- package/dist/esm/components/Inspector/NpmStarPrompt.js +58 -434
- package/dist/esm/components/Inspector/NpmUpdateToast.js +45 -281
- package/dist/esm/components/Inspector/PerformanceTab.js +393 -1570
- package/dist/esm/components/Inspector/ReduxDetail.js +307 -1170
- package/dist/esm/components/Inspector/ReduxTab.js +144 -722
- package/dist/esm/components/Inspector/SettingsPanel.js +647 -3609
- package/dist/esm/components/Inspector/SkeletonPlaceholder.js +30 -163
- package/dist/esm/components/Inspector/StorageTab.js +172 -866
- package/dist/esm/components/Inspector/TabBar.js +52 -183
- package/dist/esm/components/Inspector/UpdateAvailableModal.js +79 -416
- package/dist/esm/components/JsonViewer.js +179 -353
- package/dist/esm/components/LogCard.js +93 -565
- package/dist/esm/components/LogSyntaxHighlighter.js +11 -123
- package/dist/esm/components/MetaAccordion.js +136 -267
- package/dist/esm/components/MiniBarChart.js +3 -18
- package/dist/esm/components/MiniLineChart.js +3 -20
- package/dist/esm/components/NetworkIcons.d.ts +7 -0
- package/dist/esm/components/NetworkIcons.js +481 -817
- package/dist/esm/components/QRCodeView.js +8 -45
- package/dist/esm/components/SectionHeader.js +22 -39
- package/dist/esm/components/SegmentedTabs.js +8 -57
- package/dist/esm/components/SkeletonPlaceholder.js +30 -163
- package/dist/esm/components/Slider.js +24 -213
- package/dist/esm/components/SourcePageCard.js +65 -86
- package/dist/esm/components/Toast.js +10 -117
- package/dist/esm/components/TouchableScale.js +3 -19
- package/dist/esm/components/TreeNode.js +58 -95
- package/dist/esm/console.js +1 -2
- package/dist/esm/constants/index.js +1 -28
- package/dist/esm/constants/telemetryConfig.js +1 -3
- package/dist/esm/constants/version.d.ts +1 -1
- package/dist/esm/constants/version.js +1 -1
- package/dist/esm/crash.js +1 -2
- package/dist/esm/customHooks/analyticsLogger.js +1 -230
- package/dist/esm/customHooks/bundleAnalyzer.js +1 -944
- package/dist/esm/customHooks/consoleLogger.js +6 -432
- package/dist/esm/customHooks/crashHandler.js +7 -630
- package/dist/esm/customHooks/logFilters.js +1 -20
- package/dist/esm/customHooks/networkLogger.js +2 -519
- package/dist/esm/customHooks/performanceTracker.js +63 -723
- package/dist/esm/customHooks/reduxLogger.js +2 -293
- package/dist/esm/customHooks/storageInspector.js +1 -418
- package/dist/esm/customHooks/useAccordion.js +1 -16
- package/dist/esm/decorators/index.js +1 -95
- package/dist/esm/helpers/gaAnalyticsRegistry.js +1 -143
- package/dist/esm/helpers/index.js +8 -861
- package/dist/esm/helpers/memoryManager.js +1 -91
- package/dist/esm/helpers/qrGenerator.js +1 -364
- package/dist/esm/helpers/remoteConfig.js +1 -160
- package/dist/esm/helpers/searchQueryParser.js +1 -59
- package/dist/esm/helpers/settingsStore.js +1 -134
- package/dist/esm/helpers/telemetry.js +1 -489
- package/dist/esm/helpers/toast.js +1 -15
- package/dist/esm/i18n/index.js +1 -78
- package/dist/esm/i18n/locales/en.json +1 -1122
- package/dist/esm/index.js +7 -1967
- package/dist/esm/metro.js +6 -459
- package/dist/esm/native/NativeInspector.d.ts +3 -0
- package/dist/esm/native/NativeInspector.js +1 -370
- package/dist/esm/native/NativeNetworkInspector.d.ts +1 -0
- package/dist/esm/native/NativeNetworkInspector.js +1 -2
- package/dist/esm/network.js +1 -1
- package/dist/esm/performance.js +1 -2
- package/dist/esm/redux.js +1 -1
- package/dist/esm/storage.js +1 -1
- package/dist/esm/styles/AppColors.js +1 -417
- package/dist/esm/styles/AppFonts.js +1 -13
- package/dist/esm/styles/common.js +1 -186
- package/dist/esm/styles/index.d.ts +6 -0
- package/dist/esm/styles/index.js +1 -1551
- package/dist/esm/types/enums.d.ts +2 -1
- package/dist/esm/types/enums.js +1 -147
- package/dist/esm/types/index.js +1 -2
- package/dist/esm/types/interfaces.d.ts +7 -0
- package/dist/esm/types/interfaces.js +1 -1
- package/ios/NetworkInspectorModule.mm +253 -136
- package/package.json +5 -3
- package/react-native-inapp-inspector.podspec +1 -1
- package/src/native/NativeInspector.ts +17 -0
- package/src/native/NativeNetworkInspector.ts +1 -0
- package/src/analytics.ts +0 -35
- package/src/bundle.ts +0 -25
- package/src/capture.ts +0 -101
- package/src/components/AnalyticsDetail.tsx +0 -870
- package/src/components/AnalyticsEventCard.tsx +0 -444
- package/src/components/AnalyticsGraph.tsx +0 -583
- package/src/components/AnimatedEntrance.tsx +0 -20
- package/src/components/AppHeaderLogo.tsx +0 -143
- package/src/components/BrandCircleIcon.tsx +0 -144
- package/src/components/BrandSquareIcon.tsx +0 -184
- package/src/components/CodeSnippet.tsx +0 -725
- package/src/components/ConsoleLogCard.tsx +0 -679
- package/src/components/CopyButton.tsx +0 -87
- package/src/components/DiffViewer.tsx +0 -82
- package/src/components/DomainHeader.tsx +0 -224
- package/src/components/EmptyState.tsx +0 -95
- package/src/components/EndOfListFooter.tsx +0 -100
- package/src/components/ErrorBoundary.tsx +0 -688
- package/src/components/HeadersSection.tsx +0 -172
- package/src/components/HighlightText.tsx +0 -100
- package/src/components/Inspector/AnalyticsFilterModal.tsx +0 -1250
- package/src/components/Inspector/AnalyticsTab.tsx +0 -1362
- package/src/components/Inspector/BundleTab.tsx +0 -4768
- package/src/components/Inspector/ConsoleTab.tsx +0 -726
- package/src/components/Inspector/CrashDetail.tsx +0 -997
- package/src/components/Inspector/CrashFilterModal.tsx +0 -721
- package/src/components/Inspector/CrashTab.tsx +0 -933
- package/src/components/Inspector/DebuggingTab.tsx +0 -1103
- package/src/components/Inspector/DeviceInfoTab.tsx +0 -1397
- package/src/components/Inspector/FabLauncher.tsx +0 -80
- package/src/components/Inspector/FeatureUnderDevNotice.tsx +0 -94
- package/src/components/Inspector/FeedbackModal.tsx +0 -626
- package/src/components/Inspector/InspectorContext.tsx +0 -28
- package/src/components/Inspector/InspectorHeader.tsx +0 -1545
- package/src/components/Inspector/LogDetail.tsx +0 -1431
- package/src/components/Inspector/MainScreen.tsx +0 -459
- package/src/components/Inspector/MediaGalleryTab.tsx +0 -355
- package/src/components/Inspector/MediaPreviewModal.tsx +0 -435
- package/src/components/Inspector/NavigationTracker.tsx +0 -13
- package/src/components/Inspector/NetworkDetail.tsx +0 -795
- package/src/components/Inspector/NetworkFilterModal.tsx +0 -730
- package/src/components/Inspector/NetworkTab.tsx +0 -820
- package/src/components/Inspector/NpmStarPrompt.tsx +0 -532
- package/src/components/Inspector/NpmUpdateToast.tsx +0 -387
- package/src/components/Inspector/PerformanceTab.tsx +0 -1967
- package/src/components/Inspector/ReduxDetail.tsx +0 -1651
- package/src/components/Inspector/ReduxTab.tsx +0 -987
- package/src/components/Inspector/SettingsPanel.tsx +0 -4580
- package/src/components/Inspector/SkeletonPlaceholder.tsx +0 -206
- package/src/components/Inspector/StorageTab.tsx +0 -1159
- package/src/components/Inspector/TabBar.tsx +0 -263
- package/src/components/Inspector/UpdateAvailableModal.tsx +0 -555
- package/src/components/JsonViewer.tsx +0 -547
- package/src/components/LogCard.tsx +0 -694
- package/src/components/LogSyntaxHighlighter.tsx +0 -178
- package/src/components/MetaAccordion.tsx +0 -355
- package/src/components/MiniBarChart.tsx +0 -42
- package/src/components/MiniLineChart.tsx +0 -33
- package/src/components/NetworkIcons.tsx +0 -2599
- package/src/components/QRCodeView.tsx +0 -75
- package/src/components/SectionHeader.tsx +0 -101
- package/src/components/SegmentedTabs.tsx +0 -83
- package/src/components/SkeletonPlaceholder.tsx +0 -206
- package/src/components/Slider.tsx +0 -300
- package/src/components/SourcePageCard.tsx +0 -150
- package/src/components/Toast.tsx +0 -131
- package/src/components/TouchableScale.tsx +0 -61
- package/src/components/TreeNode.tsx +0 -171
- package/src/console.ts +0 -24
- package/src/constants/index.ts +0 -41
- package/src/constants/telemetryConfig.ts +0 -4
- package/src/constants/version.ts +0 -3
- package/src/crash.ts +0 -32
- package/src/customHooks/analyticsLogger.ts +0 -336
- package/src/customHooks/bundleAnalyzer.ts +0 -1256
- package/src/customHooks/consoleLogger.ts +0 -530
- package/src/customHooks/crashHandler.ts +0 -944
- package/src/customHooks/logFilters.ts +0 -32
- package/src/customHooks/networkLogger.ts +0 -624
- package/src/customHooks/performanceTracker.ts +0 -1014
- package/src/customHooks/reduxLogger.ts +0 -406
- package/src/customHooks/storageInspector.ts +0 -513
- package/src/customHooks/useAccordion.tsx +0 -27
- package/src/decorators/index.ts +0 -184
- package/src/helpers/gaAnalyticsRegistry.ts +0 -204
- package/src/helpers/index.ts +0 -1092
- package/src/helpers/memoryManager.ts +0 -138
- package/src/helpers/qrGenerator.ts +0 -430
- package/src/helpers/remoteConfig.ts +0 -212
- package/src/helpers/searchQueryParser.ts +0 -84
- package/src/helpers/settingsStore.ts +0 -171
- package/src/helpers/telemetry.ts +0 -568
- package/src/helpers/toast.ts +0 -17
- package/src/i18n/index.ts +0 -104
- package/src/i18n/locales/en.json +0 -1125
- package/src/index.tsx +0 -2635
- package/src/metro.ts +0 -598
- package/src/network.ts +0 -22
- package/src/performance.ts +0 -38
- package/src/redux.ts +0 -23
- package/src/storage.ts +0 -18
- package/src/styles/AppColors.ts +0 -455
- package/src/styles/AppFonts.ts +0 -26
- package/src/styles/common.ts +0 -209
- package/src/styles/index.ts +0 -1606
- package/src/types/enums.ts +0 -208
- package/src/types/index.ts +0 -34
- package/src/types/interfaces.ts +0 -530
|
@@ -1,1014 +0,0 @@
|
|
|
1
|
-
import {AppColors} from '../styles/AppColors';
|
|
2
|
-
import {t} from '../i18n';
|
|
3
|
-
import {useState, useEffect, useRef, useMemo, useCallback} from 'react';
|
|
4
|
-
|
|
5
|
-
export interface PerformanceEvent {
|
|
6
|
-
id: string;
|
|
7
|
-
timestamp: number;
|
|
8
|
-
type:
|
|
9
|
-
| 'fps_drop'
|
|
10
|
-
| 'slow_render'
|
|
11
|
-
| 'transition'
|
|
12
|
-
| 'memory'
|
|
13
|
-
| 'network'
|
|
14
|
-
| 'bridge'
|
|
15
|
-
| 'touch';
|
|
16
|
-
category: 'render' | 'navigation' | 'memory' | 'io' | 'bridge';
|
|
17
|
-
fps: number;
|
|
18
|
-
durationMs: number;
|
|
19
|
-
droppedFrames?: number;
|
|
20
|
-
frameTimeMs?: number;
|
|
21
|
-
frameBudgetPct?: number;
|
|
22
|
-
bottleneckThread?: 'JS Thread' | 'UI Thread' | 'Bridge' | 'Balanced';
|
|
23
|
-
screenName?: string;
|
|
24
|
-
label: string;
|
|
25
|
-
detail: string;
|
|
26
|
-
source?: string;
|
|
27
|
-
breakdown?: {
|
|
28
|
-
jsTimeMs: number;
|
|
29
|
-
uiTimeMs: number;
|
|
30
|
-
bridgeLatencyMs?: number;
|
|
31
|
-
};
|
|
32
|
-
heapDeltaKb?: number;
|
|
33
|
-
advice?: string;
|
|
34
|
-
severity: 'optimal' | 'warning' | 'critical';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface LiveMemoryStats {
|
|
38
|
-
heapUsedMb: number;
|
|
39
|
-
heapTotalMb: number;
|
|
40
|
-
gcCount: number;
|
|
41
|
-
gcPauseMs: number;
|
|
42
|
-
allocationRateMbPerSec: number;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface CoreMobileVitals {
|
|
46
|
-
ttiMs: number; // Time to Interactive
|
|
47
|
-
fcpMs: number; // First Contentful Paint
|
|
48
|
-
inpMs: number; // Interaction to Next Paint
|
|
49
|
-
jankPercentage: number;
|
|
50
|
-
grade: 'Optimal' | 'Fair' | 'Poor';
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface PerformanceFixKey {
|
|
54
|
-
keyName: string;
|
|
55
|
-
title: string;
|
|
56
|
-
explanation: string;
|
|
57
|
-
codeSnippet: string;
|
|
58
|
-
impact: 'High Impact' | 'Medium Impact' | 'Best Practice';
|
|
59
|
-
impactColor: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface ComponentRenderProfile {
|
|
63
|
-
id: string;
|
|
64
|
-
name: string;
|
|
65
|
-
type: 'screen' | 'component' | 'list_item' | 'modal';
|
|
66
|
-
sourceFile: string;
|
|
67
|
-
renderCount: number;
|
|
68
|
-
wastefulCount: number;
|
|
69
|
-
wastefulPercentage: number;
|
|
70
|
-
avgRenderTimeMs: number;
|
|
71
|
-
totalRenderTimeMs: number;
|
|
72
|
-
lastRenderedAt: number;
|
|
73
|
-
reasons: string[];
|
|
74
|
-
fixKeys: PerformanceFixKey[];
|
|
75
|
-
severity: 'optimal' | 'warning' | 'critical';
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Dynamically generates tailored Before/After performance optimization code snippets
|
|
80
|
-
* based on the target component's real identifier, props, and detected anti-pattern.
|
|
81
|
-
*/
|
|
82
|
-
export const generateFixSnippet = (
|
|
83
|
-
fixKey: string,
|
|
84
|
-
componentName: string = 'Component',
|
|
85
|
-
context?: {
|
|
86
|
-
propName?: string;
|
|
87
|
-
actionName?: string;
|
|
88
|
-
itemHeight?: number;
|
|
89
|
-
},
|
|
90
|
-
): PerformanceFixKey => {
|
|
91
|
-
const comp = componentName || 'Component';
|
|
92
|
-
const prop = context?.propName || 'onPress';
|
|
93
|
-
const action = context?.actionName || 'handlePress';
|
|
94
|
-
const itemHeight = context?.itemHeight || 72;
|
|
95
|
-
|
|
96
|
-
switch (fixKey) {
|
|
97
|
-
case 'useCallback':
|
|
98
|
-
return {
|
|
99
|
-
keyName: 'useCallback',
|
|
100
|
-
title: t('performance.fixUseCallbackTitle'),
|
|
101
|
-
explanation: t('performance.fixUseCallbackDesc'),
|
|
102
|
-
codeSnippet: `${t('performance.beforeUseCallback', {comp})}\n<Button ${prop}={() => ${action}(item.id)} />\n\n${t('performance.afterUseCallback')}\nconst ${action}Memo = useCallback(() => {\n ${action}(item.id);\n}, [item.id]);\n<Button ${prop}={${action}Memo} />`,
|
|
103
|
-
impact: t('performance.highImpact') as any,
|
|
104
|
-
impactColor: AppColors.pink500,
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
case 'createSelector':
|
|
108
|
-
case 'useMemo':
|
|
109
|
-
return {
|
|
110
|
-
keyName: 'createSelector',
|
|
111
|
-
title: t('performance.fixCreateSelectorTitle'),
|
|
112
|
-
explanation: t('performance.fixCreateSelectorDesc'),
|
|
113
|
-
codeSnippet: `${t('performance.beforeCreateSelector', {comp})}\nconst { items, total } = useSelector(state => ({\n items: state.cart.items,\n total: state.cart.total,\n}));\n\n${t('performance.afterCreateSelector')}\nimport { shallowEqual } from 'react-redux';\nconst { items, total } = useSelector(\n state => ({ items: state.cart.items, total: state.cart.total }),\n shallowEqual\n);`,
|
|
114
|
-
impact: t('performance.highImpact') as any,
|
|
115
|
-
impactColor: AppColors.pink500,
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
case 'memo':
|
|
119
|
-
case 'React.memo':
|
|
120
|
-
return {
|
|
121
|
-
keyName: 'memo',
|
|
122
|
-
title: t('performance.fixReactMemoTitle'),
|
|
123
|
-
explanation: t('performance.fixReactMemoDesc'),
|
|
124
|
-
codeSnippet: `${t('performance.beforeMemo', {comp})}\nexport const ${comp} = (props: ${comp}Props) => {\n return <View>...</View>;\n};\n\n${t('performance.afterMemo')}\nexport const ${comp} = React.memo((props: ${comp}Props) => {\n return <View>...</View>;\n}, (prev, next) => prev.id === next.id && prev.updatedAt === next.updatedAt);`,
|
|
125
|
-
impact: t('performance.highImpact') as any,
|
|
126
|
-
impactColor: AppColors.pink500,
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
case 'getItemLayout':
|
|
130
|
-
return {
|
|
131
|
-
keyName: 'getItemLayout',
|
|
132
|
-
title: t('performance.fixGetItemLayoutTitle'),
|
|
133
|
-
explanation: t('performance.fixGetItemLayoutDesc'),
|
|
134
|
-
codeSnippet: `${t('performance.flatListOptimization', {comp})}\nconst ITEM_HEIGHT = ${itemHeight};\nconst getItemLayout = useCallback((_data: any, index: number) => ({\n length: ITEM_HEIGHT,\n offset: ITEM_HEIGHT * index,\n index,\n}), []);\n\n<FlatList\n data={items}\n getItemLayout={getItemLayout}\n renderItem={({item}) => <${comp} item={item} />}\n keyExtractor={item => String(item.id)}\n/>`,
|
|
135
|
-
impact: t('performance.highImpact') as any,
|
|
136
|
-
impactColor: AppColors.pink500,
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
case 'customComparator':
|
|
140
|
-
return {
|
|
141
|
-
keyName: 'customComparator',
|
|
142
|
-
title: t('performance.fixCustomComparatorTitle'),
|
|
143
|
-
explanation: t('performance.fixCustomComparatorDesc'),
|
|
144
|
-
codeSnippet: `${t('performance.customComparator', {comp})}\nexport const ${comp} = React.memo(\n ${comp}Component,\n (prevProps, nextProps) => {\n return prevProps.id === nextProps.id && prevProps.status === nextProps.status;\n }\n);`,
|
|
145
|
-
impact: t('performance.mediumImpact') as any,
|
|
146
|
-
impactColor: AppColors.amber500,
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
case 'DebouncedInput':
|
|
150
|
-
return {
|
|
151
|
-
keyName: 'DebouncedInput',
|
|
152
|
-
title: t('performance.fixDebouncedInputTitle'),
|
|
153
|
-
explanation: t('performance.fixDebouncedInputDesc'),
|
|
154
|
-
codeSnippet: `${t('performance.debounceInput', {comp})}\nconst [localText, setLocalText] = useState('');\nconst debouncedSearch = useMemo(\n () => debounce((query: string) => onSearch(query), 250),\n [onSearch]\n);`,
|
|
155
|
-
impact: t('performance.highImpact') as any,
|
|
156
|
-
impactColor: AppColors.pink500,
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
case 'ComponentSplitting':
|
|
160
|
-
return {
|
|
161
|
-
keyName: 'ComponentSplitting',
|
|
162
|
-
title: t('performance.fixComponentSplittingTitle'),
|
|
163
|
-
explanation: t('performance.fixComponentSplittingDesc'),
|
|
164
|
-
codeSnippet: `${t('performance.isolateState', {comp})}\nexport const StickyKeyboard = React.memo(KeyboardStickyView);`,
|
|
165
|
-
impact: t('performance.mediumImpact') as any,
|
|
166
|
-
impactColor: AppColors.purple500,
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
case 'InteractionManager':
|
|
170
|
-
return {
|
|
171
|
-
keyName: 'InteractionManager',
|
|
172
|
-
title: t('performance.fixInteractionManagerTitle'),
|
|
173
|
-
explanation: t('performance.fixInteractionManagerDesc'),
|
|
174
|
-
codeSnippet: `${t('performance.beforeInteractionManager', {comp})}\n\n${t('performance.afterInteractionManager')}`,
|
|
175
|
-
impact: t('performance.highImpact') as any,
|
|
176
|
-
impactColor: AppColors.pink500,
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
case 'FlatListWindowing':
|
|
180
|
-
return {
|
|
181
|
-
keyName: 'FlatListWindowing',
|
|
182
|
-
title: t('performance.fixFlatListWindowingTitle'),
|
|
183
|
-
explanation: t('performance.fixFlatListWindowingDesc'),
|
|
184
|
-
codeSnippet: `${t('performance.beforeFlatListWindowing', {comp})}`,
|
|
185
|
-
impact: t('performance.mediumImpact') as any,
|
|
186
|
-
impactColor: AppColors.purple500,
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
case 'ImageCaching':
|
|
190
|
-
return {
|
|
191
|
-
keyName: 'ImageCaching',
|
|
192
|
-
title: t('performance.fixImageCachingTitle'),
|
|
193
|
-
explanation: t('performance.fixImageCachingDesc'),
|
|
194
|
-
codeSnippet: `${t('performance.beforeImageCaching', {comp})}`,
|
|
195
|
-
impact: t('performance.mediumImpact') as any,
|
|
196
|
-
impactColor: AppColors.purple500,
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
case 'ContextSplitting':
|
|
200
|
-
return {
|
|
201
|
-
keyName: 'ContextSplitting',
|
|
202
|
-
title: t('performance.fixContextSplittingTitle'),
|
|
203
|
-
explanation: t('performance.fixContextSplittingDesc'),
|
|
204
|
-
codeSnippet: `${t('performance.beforeContextSplitting', {comp})}\n\n${t('performance.afterContextSplitting')}`,
|
|
205
|
-
impact: t('performance.highImpact') as any,
|
|
206
|
-
impactColor: AppColors.pink500,
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
case 'InlineStylesHoist':
|
|
210
|
-
return {
|
|
211
|
-
keyName: 'InlineStylesHoist',
|
|
212
|
-
title: t('performance.fixInlineStylesHoistTitle'),
|
|
213
|
-
explanation: t('performance.fixInlineStylesHoistDesc'),
|
|
214
|
-
codeSnippet: `${t('performance.beforeInlineStyles', {comp})}\n\n${t('performance.afterInlineStyles')}`,
|
|
215
|
-
impact: t('performance.bestPractice') as any,
|
|
216
|
-
impactColor: AppColors.pink500,
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
case 'useRef':
|
|
220
|
-
case 'useRefForTracking':
|
|
221
|
-
default:
|
|
222
|
-
return {
|
|
223
|
-
keyName: 'useRefForTracking',
|
|
224
|
-
title: t('performance.fixUseRefForTrackingTitle'),
|
|
225
|
-
explanation: t('performance.fixUseRefForTrackingDesc'),
|
|
226
|
-
codeSnippet: `${t('performance.beforeUseRef', {comp})}\nconst [eventCount, setEventCount] = useState(0);\n\n${t('performance.afterUseRef')}\nconst eventCountRef = useRef(0);`,
|
|
227
|
-
impact: t('performance.bestPractice') as any,
|
|
228
|
-
impactColor: AppColors.pink500,
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Dynamically resolves caller file path or runtime source from the active JavaScript stack trace.
|
|
235
|
-
* Does not assume fixed directory hierarchies (such as src/ or components/) and extracts
|
|
236
|
-
* whatever relative path or symbol the host project structure uses.
|
|
237
|
-
*/
|
|
238
|
-
export function getCallerSourceFile(fallbackName?: string): string {
|
|
239
|
-
try {
|
|
240
|
-
const stack = new Error().stack;
|
|
241
|
-
if (!stack) return fallbackName || 'React Native Runtime';
|
|
242
|
-
const lines = stack.split('\n');
|
|
243
|
-
for (let i = 0; i < lines.length; i++) {
|
|
244
|
-
const line = lines[i];
|
|
245
|
-
if (
|
|
246
|
-
line.includes('performanceTracker') ||
|
|
247
|
-
line.includes('node_modules') ||
|
|
248
|
-
line.includes('Error') ||
|
|
249
|
-
line.includes('regeneratorRuntime')
|
|
250
|
-
) {
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
const match = line.match(/(?:at\s+)?(?:.*?\((.*?)(?::\d+)?(?::\d+)?\)|(\S+:\d+:\d+))/);
|
|
254
|
-
if (match) {
|
|
255
|
-
const file = (match[1] || match[2] || '').trim().replace(/^at\s+/, '');
|
|
256
|
-
if (file && !file.includes('performanceTracker')) return file;
|
|
257
|
-
}
|
|
258
|
-
const cleaned = line.trim().replace(/^at\s+/, '');
|
|
259
|
-
if (cleaned && !cleaned.includes('performanceTracker')) return cleaned;
|
|
260
|
-
}
|
|
261
|
-
} catch (e) {}
|
|
262
|
-
return fallbackName || 'React Native Runtime';
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
export const getInitialRenderProfiles = (): ComponentRenderProfile[] => [];
|
|
266
|
-
|
|
267
|
-
export const getInitialPerformanceEvents = (): PerformanceEvent[] => [];
|
|
268
|
-
|
|
269
|
-
export const INITIAL_EVENTS: PerformanceEvent[] = [];
|
|
270
|
-
|
|
271
|
-
let isPerformanceModuleEnabled = false;
|
|
272
|
-
|
|
273
|
-
export const setPerformanceModuleEnabled = (enabled: boolean) => {
|
|
274
|
-
isPerformanceModuleEnabled = enabled;
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
export const getPerformanceModuleEnabled = () => isPerformanceModuleEnabled;
|
|
278
|
-
|
|
279
|
-
const globalRenderRegistry = new Map<string, ComponentRenderProfile>();
|
|
280
|
-
const renderListeners = new Set<(profiles: ComponentRenderProfile[]) => void>();
|
|
281
|
-
|
|
282
|
-
const notifyRenderListeners = () => {
|
|
283
|
-
const list = Array.from(globalRenderRegistry.values());
|
|
284
|
-
renderListeners.forEach(listener => {
|
|
285
|
-
try {
|
|
286
|
-
listener(list);
|
|
287
|
-
} catch {}
|
|
288
|
-
});
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
export const subscribeRenderProfiles = (
|
|
292
|
-
listener: (profiles: ComponentRenderProfile[]) => void,
|
|
293
|
-
) => {
|
|
294
|
-
renderListeners.add(listener);
|
|
295
|
-
listener(Array.from(globalRenderRegistry.values()));
|
|
296
|
-
return () => {
|
|
297
|
-
renderListeners.delete(listener);
|
|
298
|
-
};
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
export const getRenderProfiles = () => Array.from(globalRenderRegistry.values());
|
|
302
|
-
|
|
303
|
-
export const registerComponentProfile = (profile: ComponentRenderProfile) => {
|
|
304
|
-
if (!isPerformanceModuleEnabled) return;
|
|
305
|
-
globalRenderRegistry.set(profile.name, profile);
|
|
306
|
-
notifyRenderListeners();
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
export const trackComponentRender = (params: {
|
|
310
|
-
name: string;
|
|
311
|
-
type?: ComponentRenderProfile['type'];
|
|
312
|
-
sourceFile?: string;
|
|
313
|
-
renderTimeMs?: number;
|
|
314
|
-
isWasteful?: boolean;
|
|
315
|
-
reason?: string;
|
|
316
|
-
fixKeys?: PerformanceFixKey[];
|
|
317
|
-
}) => {
|
|
318
|
-
if (!isPerformanceModuleEnabled) return;
|
|
319
|
-
const existing = globalRenderRegistry.get(params.name);
|
|
320
|
-
const now = Date.now();
|
|
321
|
-
const renderTimeMs = params.renderTimeMs ?? 1.5;
|
|
322
|
-
const isWasteful = params.isWasteful ?? false;
|
|
323
|
-
|
|
324
|
-
if (existing) {
|
|
325
|
-
const nextCount = existing.renderCount + 1;
|
|
326
|
-
const nextWasteful = existing.wastefulCount + (isWasteful ? 1 : 0);
|
|
327
|
-
const nextPct = Number(((nextWasteful / nextCount) * 100).toFixed(1));
|
|
328
|
-
const nextTotalTime = Number(
|
|
329
|
-
(existing.totalRenderTimeMs + renderTimeMs).toFixed(1),
|
|
330
|
-
);
|
|
331
|
-
const nextAvgTime = Number((nextTotalTime / nextCount).toFixed(1));
|
|
332
|
-
const reasons = params.reason
|
|
333
|
-
? Array.from(new Set([...existing.reasons, params.reason]))
|
|
334
|
-
: existing.reasons;
|
|
335
|
-
|
|
336
|
-
const updated: ComponentRenderProfile = {
|
|
337
|
-
...existing,
|
|
338
|
-
renderCount: nextCount,
|
|
339
|
-
wastefulCount: nextWasteful,
|
|
340
|
-
wastefulPercentage: nextPct,
|
|
341
|
-
avgRenderTimeMs: nextAvgTime,
|
|
342
|
-
totalRenderTimeMs: nextTotalTime,
|
|
343
|
-
lastRenderedAt: now,
|
|
344
|
-
reasons,
|
|
345
|
-
severity:
|
|
346
|
-
nextPct > 70 && nextCount > 20
|
|
347
|
-
? 'critical'
|
|
348
|
-
: nextPct > 40 && nextCount > 10
|
|
349
|
-
? 'warning'
|
|
350
|
-
: 'optimal',
|
|
351
|
-
};
|
|
352
|
-
globalRenderRegistry.set(params.name, updated);
|
|
353
|
-
} else {
|
|
354
|
-
const profile: ComponentRenderProfile = {
|
|
355
|
-
id: `render-${Date.now()}-${Math.random().toString(36).substring(2, 6)}`,
|
|
356
|
-
name: params.name,
|
|
357
|
-
type: params.type || 'component',
|
|
358
|
-
sourceFile: params.sourceFile || getCallerSourceFile(params.name),
|
|
359
|
-
renderCount: 1,
|
|
360
|
-
wastefulCount: isWasteful ? 1 : 0,
|
|
361
|
-
wastefulPercentage: isWasteful ? 100 : 0,
|
|
362
|
-
avgRenderTimeMs: renderTimeMs,
|
|
363
|
-
totalRenderTimeMs: renderTimeMs,
|
|
364
|
-
lastRenderedAt: now,
|
|
365
|
-
reasons: params.reason ? [params.reason] : [],
|
|
366
|
-
fixKeys:
|
|
367
|
-
params.fixKeys || [
|
|
368
|
-
generateFixSnippet('useCallback', params.name),
|
|
369
|
-
generateFixSnippet('memo', params.name),
|
|
370
|
-
],
|
|
371
|
-
severity: 'optimal',
|
|
372
|
-
};
|
|
373
|
-
globalRenderRegistry.set(params.name, profile);
|
|
374
|
-
}
|
|
375
|
-
notifyRenderListeners();
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Dynamically queries Hermes or JavaScript runtime memory statistics.
|
|
380
|
-
*/
|
|
381
|
-
export const getHermesMemoryStats = (): LiveMemoryStats => {
|
|
382
|
-
try {
|
|
383
|
-
const hermes = (globalThis as any).HermesInternal;
|
|
384
|
-
if (hermes && typeof hermes.getInstrumentedStats === 'function') {
|
|
385
|
-
const stats = hermes.getInstrumentedStats();
|
|
386
|
-
const heapUsedMb = Number(
|
|
387
|
-
(
|
|
388
|
-
(stats.js_heap_size || stats.heap_size || 34800000) / 1048576
|
|
389
|
-
).toFixed(1),
|
|
390
|
-
);
|
|
391
|
-
const heapTotalMb = Number(
|
|
392
|
-
(
|
|
393
|
-
(stats.js_heap_capacity || stats.allocated_bytes || 64000000) /
|
|
394
|
-
1048576
|
|
395
|
-
).toFixed(1),
|
|
396
|
-
);
|
|
397
|
-
const gcCount = Number(stats.num_gcs || 0);
|
|
398
|
-
const gcPauseMs = Number(
|
|
399
|
-
((stats.gc_time_ms || 0) / Math.max(1, gcCount)).toFixed(1),
|
|
400
|
-
);
|
|
401
|
-
return {
|
|
402
|
-
heapUsedMb,
|
|
403
|
-
heapTotalMb,
|
|
404
|
-
gcCount,
|
|
405
|
-
gcPauseMs,
|
|
406
|
-
allocationRateMbPerSec: 1.8,
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
} catch {}
|
|
410
|
-
return {
|
|
411
|
-
heapUsedMb: 32.5,
|
|
412
|
-
heapTotalMb: 64.0,
|
|
413
|
-
gcCount: 0,
|
|
414
|
-
gcPauseMs: 1.5,
|
|
415
|
-
allocationRateMbPerSec: 1.2,
|
|
416
|
-
};
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Dynamically records and evaluates screen navigation transition performance.
|
|
421
|
-
*/
|
|
422
|
-
export const trackNavigationTransition = (
|
|
423
|
-
screenName: string,
|
|
424
|
-
durationMs: number,
|
|
425
|
-
options?: {
|
|
426
|
-
ttiMs?: number;
|
|
427
|
-
droppedFrames?: number;
|
|
428
|
-
source?: string;
|
|
429
|
-
},
|
|
430
|
-
) => {
|
|
431
|
-
const duration = Math.max(1, Number(durationMs.toFixed(1)));
|
|
432
|
-
const tti = options?.ttiMs ? Number(options.ttiMs.toFixed(1)) : duration;
|
|
433
|
-
const droppedFrames =
|
|
434
|
-
options?.droppedFrames ??
|
|
435
|
-
(duration > 32 ? Math.round((duration - 16.67) / 16.67) : 0);
|
|
436
|
-
const fps = Math.min(
|
|
437
|
-
60,
|
|
438
|
-
Math.max(15, Math.round(1000 / Math.max(16.67, duration))),
|
|
439
|
-
);
|
|
440
|
-
|
|
441
|
-
return logPerformanceEvent({
|
|
442
|
-
type: 'transition',
|
|
443
|
-
category: 'navigation',
|
|
444
|
-
fps,
|
|
445
|
-
durationMs: duration,
|
|
446
|
-
droppedFrames,
|
|
447
|
-
frameTimeMs: duration,
|
|
448
|
-
frameBudgetPct: Number(((duration / 16.67) * 100).toFixed(0)),
|
|
449
|
-
bottleneckThread: duration > 32 ? 'JS Thread' : 'Balanced',
|
|
450
|
-
screenName,
|
|
451
|
-
label: t('performance.transitionEventLabel', {screen: screenName}),
|
|
452
|
-
detail: t('performance.transitionEventDetail', {duration, tti}),
|
|
453
|
-
source: options?.source || getCallerSourceFile(screenName),
|
|
454
|
-
advice: t('performance.transitionEventAdvice'),
|
|
455
|
-
severity: duration > 50 ? 'critical' : duration > 25 ? 'warning' : 'optimal',
|
|
456
|
-
});
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* React Hook that automatically profiles screen mounts and navigation transitions.
|
|
461
|
-
*/
|
|
462
|
-
export const useNavigationProfiler = (
|
|
463
|
-
screenName: string,
|
|
464
|
-
options?: {
|
|
465
|
-
onTransitionEnd?: (durationMs: number) => void;
|
|
466
|
-
},
|
|
467
|
-
) => {
|
|
468
|
-
const mountTimeRef = useRef(Date.now());
|
|
469
|
-
|
|
470
|
-
useEffect(() => {
|
|
471
|
-
const elapsed = Date.now() - mountTimeRef.current;
|
|
472
|
-
trackNavigationTransition(screenName, elapsed);
|
|
473
|
-
if (options?.onTransitionEnd) {
|
|
474
|
-
options.onTransitionEnd(elapsed);
|
|
475
|
-
}
|
|
476
|
-
}, [screenName]);
|
|
477
|
-
};
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Measures synchronous execution duration and alerts on frame budget spikes (>16ms).
|
|
481
|
-
*/
|
|
482
|
-
export const trackHeavyTask = <T>(
|
|
483
|
-
taskName: string,
|
|
484
|
-
syncFn: () => T,
|
|
485
|
-
options?: {
|
|
486
|
-
thresholdMs?: number;
|
|
487
|
-
source?: string;
|
|
488
|
-
},
|
|
489
|
-
): T => {
|
|
490
|
-
const start = Date.now();
|
|
491
|
-
try {
|
|
492
|
-
return syncFn();
|
|
493
|
-
} finally {
|
|
494
|
-
const duration = Date.now() - start;
|
|
495
|
-
const threshold = options?.thresholdMs ?? 16;
|
|
496
|
-
if (duration >= threshold) {
|
|
497
|
-
logPerformanceEvent({
|
|
498
|
-
type: 'slow_render',
|
|
499
|
-
category: 'render',
|
|
500
|
-
fps: Math.min(60, Math.max(10, Math.round(1000 / duration))),
|
|
501
|
-
durationMs: duration,
|
|
502
|
-
frameTimeMs: duration,
|
|
503
|
-
frameBudgetPct: Number(((duration / 16.67) * 100).toFixed(0)),
|
|
504
|
-
bottleneckThread: 'JS Thread',
|
|
505
|
-
screenName: taskName,
|
|
506
|
-
label: t('performance.heavyTaskEventLabel', {taskName}),
|
|
507
|
-
detail: t('performance.heavyTaskEventDetail', {duration}),
|
|
508
|
-
source: options?.source || getCallerSourceFile(taskName),
|
|
509
|
-
advice: t('performance.heavyTaskEventAdvice'),
|
|
510
|
-
severity: duration > 50 ? 'critical' : 'warning',
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
|
|
516
|
-
/**
|
|
517
|
-
* Measures async operation / Promise latency and records slow network or disk tasks.
|
|
518
|
-
*/
|
|
519
|
-
export const measureAsync = async <T>(
|
|
520
|
-
taskName: string,
|
|
521
|
-
asyncFn: () => Promise<T>,
|
|
522
|
-
options?: {
|
|
523
|
-
thresholdMs?: number;
|
|
524
|
-
source?: string;
|
|
525
|
-
},
|
|
526
|
-
): Promise<T> => {
|
|
527
|
-
const start = Date.now();
|
|
528
|
-
try {
|
|
529
|
-
return await asyncFn();
|
|
530
|
-
} finally {
|
|
531
|
-
const duration = Date.now() - start;
|
|
532
|
-
const threshold = options?.thresholdMs ?? 100;
|
|
533
|
-
if (duration >= threshold) {
|
|
534
|
-
logPerformanceEvent({
|
|
535
|
-
type: 'network',
|
|
536
|
-
category: 'io',
|
|
537
|
-
fps: 60,
|
|
538
|
-
durationMs: duration,
|
|
539
|
-
bottleneckThread: 'Balanced',
|
|
540
|
-
screenName: taskName,
|
|
541
|
-
label: t('performance.asyncOpEventLabel', {opName: taskName}),
|
|
542
|
-
detail: t('performance.asyncOpEventDetail', {duration}),
|
|
543
|
-
source: options?.source || getCallerSourceFile(taskName),
|
|
544
|
-
severity:
|
|
545
|
-
duration > 1000 ? 'critical' : duration > 300 ? 'warning' : 'optimal',
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
};
|
|
550
|
-
|
|
551
|
-
/**
|
|
552
|
-
* Custom React Hook to profile any component or screen renders dynamically in runtime.
|
|
553
|
-
*/
|
|
554
|
-
export const useComponentProfiler = (
|
|
555
|
-
componentName: string,
|
|
556
|
-
options?: {
|
|
557
|
-
type?: ComponentRenderProfile['type'];
|
|
558
|
-
sourceFile?: string;
|
|
559
|
-
propsToCompare?: Record<string, any>;
|
|
560
|
-
},
|
|
561
|
-
) => {
|
|
562
|
-
const renderCountRef = useRef(0);
|
|
563
|
-
const prevPropsRef = useRef<any>(options?.propsToCompare);
|
|
564
|
-
const startTimeRef = useRef(Date.now());
|
|
565
|
-
const renderTimestampsRef = useRef<number[]>([]);
|
|
566
|
-
startTimeRef.current = Date.now();
|
|
567
|
-
|
|
568
|
-
useEffect(() => {
|
|
569
|
-
const duration = Date.now() - startTimeRef.current;
|
|
570
|
-
const now = Date.now();
|
|
571
|
-
renderCountRef.current += 1;
|
|
572
|
-
|
|
573
|
-
// Detect rapid re-render loop spikes (>= 10 renders within 500ms)
|
|
574
|
-
renderTimestampsRef.current = [
|
|
575
|
-
...renderTimestampsRef.current.filter(ts => now - ts <= 500),
|
|
576
|
-
now,
|
|
577
|
-
];
|
|
578
|
-
if (renderTimestampsRef.current.length >= 10) {
|
|
579
|
-
logPerformanceEvent({
|
|
580
|
-
type: 'slow_render',
|
|
581
|
-
category: 'render',
|
|
582
|
-
fps: 20,
|
|
583
|
-
durationMs: duration,
|
|
584
|
-
bottleneckThread: 'JS Thread',
|
|
585
|
-
screenName: componentName,
|
|
586
|
-
label: t('performance.renderLoopWarningLabel', {comp: componentName}),
|
|
587
|
-
detail: t('performance.renderLoopWarningDetail', {
|
|
588
|
-
comp: componentName,
|
|
589
|
-
count: renderTimestampsRef.current.length,
|
|
590
|
-
}),
|
|
591
|
-
source: options?.sourceFile || getCallerSourceFile(componentName),
|
|
592
|
-
advice: t('performance.renderLoopWarningAdvice'),
|
|
593
|
-
severity: 'critical',
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
let isWasteful = false;
|
|
598
|
-
let wastefulReason = undefined;
|
|
599
|
-
|
|
600
|
-
if (renderCountRef.current > 1 && options?.propsToCompare) {
|
|
601
|
-
const prev = prevPropsRef.current;
|
|
602
|
-
const next = options.propsToCompare;
|
|
603
|
-
const keys = Object.keys(next);
|
|
604
|
-
const changedKeys = keys.filter(k => prev[k] !== next[k]);
|
|
605
|
-
if (changedKeys.length === 0) {
|
|
606
|
-
isWasteful = true;
|
|
607
|
-
wastefulReason =
|
|
608
|
-
'Re-rendered with identical props (memoization candidate)';
|
|
609
|
-
}
|
|
610
|
-
prevPropsRef.current = next;
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
trackComponentRender({
|
|
614
|
-
name: componentName,
|
|
615
|
-
type: options?.type || 'component',
|
|
616
|
-
sourceFile: options?.sourceFile || getCallerSourceFile(componentName),
|
|
617
|
-
renderTimeMs: Math.max(0.5, duration),
|
|
618
|
-
isWasteful,
|
|
619
|
-
reason: wastefulReason,
|
|
620
|
-
});
|
|
621
|
-
});
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
export const usePerformanceTracker = (enabled: boolean = true) => {
|
|
625
|
-
const isTrackerActive = enabled && isPerformanceModuleEnabled;
|
|
626
|
-
const [isRecording, setIsRecording] = useState(true);
|
|
627
|
-
const [currentFps, setCurrentFps] = useState(60);
|
|
628
|
-
const [minFps, setMinFps] = useState(60);
|
|
629
|
-
const [maxFps, setMaxFps] = useState(60);
|
|
630
|
-
const [avgFps, setAvgFps] = useState(60);
|
|
631
|
-
const [totalFrames, setTotalFrames] = useState(0);
|
|
632
|
-
const [jankyFrameCount, setJankyFrameCount] = useState(0);
|
|
633
|
-
const [jsLagMs, setJsLagMs] = useState(0);
|
|
634
|
-
const [fpsHistory, setFpsHistory] = useState<number[]>(() =>
|
|
635
|
-
Array(30).fill(60),
|
|
636
|
-
);
|
|
637
|
-
|
|
638
|
-
const [memoryStats, setMemoryStats] = useState<LiveMemoryStats>(() =>
|
|
639
|
-
getHermesMemoryStats(),
|
|
640
|
-
);
|
|
641
|
-
|
|
642
|
-
const [renderProfiles, setRenderProfiles] = useState<
|
|
643
|
-
ComponentRenderProfile[]
|
|
644
|
-
>(() => getRenderProfiles());
|
|
645
|
-
const [events, setEvents] = useState<PerformanceEvent[]>(() =>
|
|
646
|
-
getPerformanceEvents(),
|
|
647
|
-
);
|
|
648
|
-
|
|
649
|
-
useEffect(() => {
|
|
650
|
-
if (!isTrackerActive) return;
|
|
651
|
-
const unsubRender = subscribeRenderProfiles(profiles => {
|
|
652
|
-
setRenderProfiles(profiles);
|
|
653
|
-
});
|
|
654
|
-
const unsubEvents = subscribePerformanceEvents(liveEvents => {
|
|
655
|
-
setEvents(liveEvents);
|
|
656
|
-
});
|
|
657
|
-
return () => {
|
|
658
|
-
unsubRender();
|
|
659
|
-
unsubEvents();
|
|
660
|
-
};
|
|
661
|
-
}, [isTrackerActive]);
|
|
662
|
-
|
|
663
|
-
const lastFrameTimeRef = useRef<number>(Date.now());
|
|
664
|
-
const rafIdRef = useRef<number | null>(null);
|
|
665
|
-
const appStartTimestampRef = useRef<number>(Date.now());
|
|
666
|
-
|
|
667
|
-
// Live Frame Measurement Loop
|
|
668
|
-
useEffect(() => {
|
|
669
|
-
if (!isTrackerActive || !isRecording) return;
|
|
670
|
-
|
|
671
|
-
let isMounted = true;
|
|
672
|
-
let frameCount = 0;
|
|
673
|
-
let maxLagInSecond = 0;
|
|
674
|
-
let lastSecond = Date.now();
|
|
675
|
-
|
|
676
|
-
const measureFrame = () => {
|
|
677
|
-
if (!isMounted) return;
|
|
678
|
-
|
|
679
|
-
const now = Date.now();
|
|
680
|
-
const delta = now - lastFrameTimeRef.current;
|
|
681
|
-
lastFrameTimeRef.current = now;
|
|
682
|
-
|
|
683
|
-
const lag = Math.max(0, delta - 16.67);
|
|
684
|
-
if (lag > maxLagInSecond) {
|
|
685
|
-
maxLagInSecond = lag;
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
frameCount++;
|
|
689
|
-
|
|
690
|
-
if (now - lastSecond >= 1000) {
|
|
691
|
-
const elapsed = now - lastSecond;
|
|
692
|
-
const measuredFps = Math.min(
|
|
693
|
-
60,
|
|
694
|
-
Math.max(0, Math.round((frameCount * 1000) / elapsed)),
|
|
695
|
-
);
|
|
696
|
-
|
|
697
|
-
setCurrentFps(measuredFps);
|
|
698
|
-
setMinFps(prev => Math.min(prev, measuredFps));
|
|
699
|
-
setMaxFps(prev => Math.max(prev, measuredFps));
|
|
700
|
-
setTotalFrames(prev => prev + frameCount);
|
|
701
|
-
setJsLagMs(Number(maxLagInSecond.toFixed(1)));
|
|
702
|
-
|
|
703
|
-
if (measuredFps < 55) {
|
|
704
|
-
setJankyFrameCount(prev => prev + 1);
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
setFpsHistory(prev => {
|
|
708
|
-
const next = [...prev.slice(-29), measuredFps];
|
|
709
|
-
const sum = next.reduce((a, b) => a + b, 0);
|
|
710
|
-
setAvgFps(Math.round(sum / next.length));
|
|
711
|
-
return next;
|
|
712
|
-
});
|
|
713
|
-
|
|
714
|
-
// Update live memory telemetry from Hermes / engine
|
|
715
|
-
const liveMem = getHermesMemoryStats();
|
|
716
|
-
setMemoryStats(prev => ({
|
|
717
|
-
...prev,
|
|
718
|
-
heapUsedMb: liveMem.heapUsedMb,
|
|
719
|
-
heapTotalMb: liveMem.heapTotalMb,
|
|
720
|
-
gcCount: liveMem.gcCount,
|
|
721
|
-
gcPauseMs: liveMem.gcPauseMs,
|
|
722
|
-
allocationRateMbPerSec: liveMem.allocationRateMbPerSec,
|
|
723
|
-
}));
|
|
724
|
-
|
|
725
|
-
if (measuredFps < 50) {
|
|
726
|
-
const frameTime = Number((1000 / measuredFps).toFixed(1));
|
|
727
|
-
logPerformanceEvent({
|
|
728
|
-
type: 'fps_drop',
|
|
729
|
-
category: 'render',
|
|
730
|
-
fps: measuredFps,
|
|
731
|
-
durationMs: frameTime,
|
|
732
|
-
droppedFrames: Math.max(0, 60 - measuredFps),
|
|
733
|
-
frameTimeMs: frameTime,
|
|
734
|
-
frameBudgetPct: Number(((frameTime / 16.67) * 100).toFixed(0)),
|
|
735
|
-
bottleneckThread: maxLagInSecond > 8 ? 'JS Thread' : 'UI Thread',
|
|
736
|
-
screenName: 'Live Application Render',
|
|
737
|
-
label: t('performance.liveFpsDropLabel', {fps: measuredFps}),
|
|
738
|
-
detail: t('performance.liveFpsDropDetail', {duration: frameTime}),
|
|
739
|
-
source: 'React Native UI Thread',
|
|
740
|
-
breakdown: {
|
|
741
|
-
jsTimeMs: Number((frameTime * 0.65).toFixed(1)),
|
|
742
|
-
uiTimeMs: Number((frameTime * 0.35).toFixed(1)),
|
|
743
|
-
},
|
|
744
|
-
advice: t('performance.liveFpsDropAdvice'),
|
|
745
|
-
severity: measuredFps < 30 ? 'critical' : 'warning',
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
frameCount = 0;
|
|
750
|
-
maxLagInSecond = 0;
|
|
751
|
-
lastSecond = now;
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
rafIdRef.current = requestAnimationFrame(measureFrame);
|
|
755
|
-
};
|
|
756
|
-
|
|
757
|
-
lastFrameTimeRef.current = Date.now();
|
|
758
|
-
rafIdRef.current = requestAnimationFrame(measureFrame);
|
|
759
|
-
|
|
760
|
-
return () => {
|
|
761
|
-
isMounted = false;
|
|
762
|
-
if (rafIdRef.current) cancelAnimationFrame(rafIdRef.current);
|
|
763
|
-
};
|
|
764
|
-
}, [isRecording]);
|
|
765
|
-
|
|
766
|
-
const mobileVitals: CoreMobileVitals = useMemo(() => {
|
|
767
|
-
const measuredJankPct =
|
|
768
|
-
totalFrames > 0
|
|
769
|
-
? Number(
|
|
770
|
-
((jankyFrameCount / Math.max(1, totalFrames / 60)) * 100).toFixed(
|
|
771
|
-
1,
|
|
772
|
-
),
|
|
773
|
-
)
|
|
774
|
-
: 0;
|
|
775
|
-
|
|
776
|
-
const slowRenderCount = events.filter(e => e.type === 'slow_render').length;
|
|
777
|
-
const dynamicInp = Math.min(
|
|
778
|
-
100,
|
|
779
|
-
Math.max(8.0, Number((jsLagMs + 12.5).toFixed(1))),
|
|
780
|
-
);
|
|
781
|
-
const dynamicFcp = Math.max(
|
|
782
|
-
120,
|
|
783
|
-
Math.min(500, Math.round(150 + slowRenderCount * 25)),
|
|
784
|
-
);
|
|
785
|
-
const dynamicTti = Math.max(
|
|
786
|
-
280,
|
|
787
|
-
Math.min(1200, Math.round(dynamicFcp + 180 + slowRenderCount * 40)),
|
|
788
|
-
);
|
|
789
|
-
|
|
790
|
-
return {
|
|
791
|
-
ttiMs: dynamicTti,
|
|
792
|
-
fcpMs: dynamicFcp,
|
|
793
|
-
inpMs: dynamicInp,
|
|
794
|
-
jankPercentage: measuredJankPct,
|
|
795
|
-
grade:
|
|
796
|
-
measuredJankPct <= 2.0
|
|
797
|
-
? 'Optimal'
|
|
798
|
-
: measuredJankPct <= 5.0
|
|
799
|
-
? 'Fair'
|
|
800
|
-
: 'Poor',
|
|
801
|
-
};
|
|
802
|
-
}, [totalFrames, jankyFrameCount, jsLagMs, events]);
|
|
803
|
-
|
|
804
|
-
// Aggregate re-render stats
|
|
805
|
-
const reRenderSummary = useMemo(() => {
|
|
806
|
-
const totalRenders = renderProfiles.reduce(
|
|
807
|
-
(sum, p) => sum + p.renderCount,
|
|
808
|
-
0,
|
|
809
|
-
);
|
|
810
|
-
const totalWasteful = renderProfiles.reduce(
|
|
811
|
-
(sum, p) => sum + p.wastefulCount,
|
|
812
|
-
0,
|
|
813
|
-
);
|
|
814
|
-
const overallWastefulPct =
|
|
815
|
-
totalRenders > 0
|
|
816
|
-
? Number(((totalWasteful / totalRenders) * 100).toFixed(1))
|
|
817
|
-
: 0;
|
|
818
|
-
const topOffender = [...renderProfiles].sort(
|
|
819
|
-
(a, b) => b.renderCount - a.renderCount,
|
|
820
|
-
)[0];
|
|
821
|
-
|
|
822
|
-
return {
|
|
823
|
-
totalRenders,
|
|
824
|
-
totalWasteful,
|
|
825
|
-
overallWastefulPct,
|
|
826
|
-
topOffender,
|
|
827
|
-
totalComponentsTracked: renderProfiles.length,
|
|
828
|
-
};
|
|
829
|
-
}, [renderProfiles]);
|
|
830
|
-
|
|
831
|
-
const clearEvents = () => {
|
|
832
|
-
clearPerformanceEvents();
|
|
833
|
-
};
|
|
834
|
-
|
|
835
|
-
const resetRenderCounters = useCallback(() => {
|
|
836
|
-
globalRenderRegistry.forEach((p, key) => {
|
|
837
|
-
globalRenderRegistry.set(key, {
|
|
838
|
-
...p,
|
|
839
|
-
renderCount: 1,
|
|
840
|
-
wastefulCount: 0,
|
|
841
|
-
wastefulPercentage: 0,
|
|
842
|
-
totalRenderTimeMs: p.avgRenderTimeMs,
|
|
843
|
-
lastRenderedAt: Date.now(),
|
|
844
|
-
severity: 'optimal',
|
|
845
|
-
});
|
|
846
|
-
});
|
|
847
|
-
notifyRenderListeners();
|
|
848
|
-
}, []);
|
|
849
|
-
|
|
850
|
-
const simulateComponentRender = useCallback((componentId: string) => {
|
|
851
|
-
globalRenderRegistry.forEach((p, key) => {
|
|
852
|
-
if (p.id === componentId || p.name === componentId) {
|
|
853
|
-
const nextCount = p.renderCount + 1;
|
|
854
|
-
const nextWasteful = p.wastefulCount + 1;
|
|
855
|
-
const nextPct = Number(((nextWasteful / nextCount) * 100).toFixed(1));
|
|
856
|
-
globalRenderRegistry.set(key, {
|
|
857
|
-
...p,
|
|
858
|
-
renderCount: nextCount,
|
|
859
|
-
wastefulCount: nextWasteful,
|
|
860
|
-
wastefulPercentage: nextPct,
|
|
861
|
-
totalRenderTimeMs: Number(
|
|
862
|
-
(p.totalRenderTimeMs + p.avgRenderTimeMs).toFixed(1),
|
|
863
|
-
),
|
|
864
|
-
lastRenderedAt: Date.now(),
|
|
865
|
-
severity:
|
|
866
|
-
nextCount > 30
|
|
867
|
-
? 'critical'
|
|
868
|
-
: nextCount > 15
|
|
869
|
-
? 'warning'
|
|
870
|
-
: 'optimal',
|
|
871
|
-
});
|
|
872
|
-
}
|
|
873
|
-
});
|
|
874
|
-
notifyRenderListeners();
|
|
875
|
-
}, []);
|
|
876
|
-
|
|
877
|
-
const triggerGc = () => {
|
|
878
|
-
try {
|
|
879
|
-
if (typeof (globalThis as any).gc === 'function') {
|
|
880
|
-
(globalThis as any).gc();
|
|
881
|
-
}
|
|
882
|
-
} catch {}
|
|
883
|
-
|
|
884
|
-
const reclaimedMb = Number((4.5 + Math.random() * 3.5).toFixed(1));
|
|
885
|
-
const reclaimedKb = Math.round(reclaimedMb * 1024);
|
|
886
|
-
|
|
887
|
-
setMemoryStats(prev => ({
|
|
888
|
-
...prev,
|
|
889
|
-
heapUsedMb: Math.max(
|
|
890
|
-
18.0,
|
|
891
|
-
Number((prev.heapUsedMb - reclaimedMb).toFixed(1)),
|
|
892
|
-
),
|
|
893
|
-
gcCount: prev.gcCount + 1,
|
|
894
|
-
gcPauseMs: Number((1.2 + Math.random() * 0.9).toFixed(1)),
|
|
895
|
-
}));
|
|
896
|
-
|
|
897
|
-
logPerformanceEvent({
|
|
898
|
-
type: 'memory',
|
|
899
|
-
category: 'memory',
|
|
900
|
-
fps: 60,
|
|
901
|
-
durationMs: Number((1.6 + Math.random() * 0.8).toFixed(1)),
|
|
902
|
-
label: t('performance.gcCycleLabel'),
|
|
903
|
-
detail: t('performance.gcCycleDetail', {amount: reclaimedMb}),
|
|
904
|
-
source: 'Hermes JavaScript VM Scavenger',
|
|
905
|
-
breakdown: {jsTimeMs: 1.8, uiTimeMs: 0.3},
|
|
906
|
-
heapDeltaKb: -reclaimedKb,
|
|
907
|
-
advice: t('performance.gcCycleAdvice'),
|
|
908
|
-
severity: 'optimal',
|
|
909
|
-
});
|
|
910
|
-
};
|
|
911
|
-
|
|
912
|
-
return {
|
|
913
|
-
isRecording,
|
|
914
|
-
setIsRecording,
|
|
915
|
-
currentFps,
|
|
916
|
-
minFps,
|
|
917
|
-
maxFps,
|
|
918
|
-
avgFps,
|
|
919
|
-
totalFrames,
|
|
920
|
-
jankyFrameCount,
|
|
921
|
-
jsLagMs,
|
|
922
|
-
fpsHistory,
|
|
923
|
-
memoryStats,
|
|
924
|
-
mobileVitals,
|
|
925
|
-
renderProfiles,
|
|
926
|
-
reRenderSummary,
|
|
927
|
-
resetRenderCounters,
|
|
928
|
-
simulateComponentRender,
|
|
929
|
-
events,
|
|
930
|
-
setEvents,
|
|
931
|
-
clearEvents,
|
|
932
|
-
triggerGc,
|
|
933
|
-
};
|
|
934
|
-
};
|
|
935
|
-
|
|
936
|
-
const globalPerformanceEvents: PerformanceEvent[] = [...INITIAL_EVENTS];
|
|
937
|
-
const performanceListeners = new Set<(events: PerformanceEvent[]) => void>();
|
|
938
|
-
|
|
939
|
-
let maxPerformanceEventsLimit = 100;
|
|
940
|
-
|
|
941
|
-
export const setMaxPerformanceEventsLimit = (limit: number): void => {
|
|
942
|
-
maxPerformanceEventsLimit = Math.max(10, limit);
|
|
943
|
-
if (globalPerformanceEvents.length > maxPerformanceEventsLimit) {
|
|
944
|
-
globalPerformanceEvents.length = maxPerformanceEventsLimit;
|
|
945
|
-
performanceListeners.forEach(listener => {
|
|
946
|
-
try {
|
|
947
|
-
listener([...globalPerformanceEvents]);
|
|
948
|
-
} catch {}
|
|
949
|
-
});
|
|
950
|
-
}
|
|
951
|
-
};
|
|
952
|
-
|
|
953
|
-
export const getMaxPerformanceEventsLimit = (): number => maxPerformanceEventsLimit;
|
|
954
|
-
|
|
955
|
-
export const prunePerformanceEvents = (targetCount?: number): number => {
|
|
956
|
-
const countToKeep = targetCount !== undefined ? Math.max(0, targetCount) : Math.floor(globalPerformanceEvents.length / 2);
|
|
957
|
-
const pruned = globalPerformanceEvents.length - countToKeep;
|
|
958
|
-
if (pruned > 0) {
|
|
959
|
-
globalPerformanceEvents.length = countToKeep;
|
|
960
|
-
performanceListeners.forEach(listener => {
|
|
961
|
-
try {
|
|
962
|
-
listener([...globalPerformanceEvents]);
|
|
963
|
-
} catch {}
|
|
964
|
-
});
|
|
965
|
-
}
|
|
966
|
-
return Math.max(0, pruned);
|
|
967
|
-
};
|
|
968
|
-
|
|
969
|
-
export const logPerformanceEvent = (
|
|
970
|
-
event: Omit<PerformanceEvent, 'id' | 'timestamp'> & {
|
|
971
|
-
id?: string;
|
|
972
|
-
timestamp?: number;
|
|
973
|
-
},
|
|
974
|
-
) => {
|
|
975
|
-
const fullEvent: PerformanceEvent = {
|
|
976
|
-
id:
|
|
977
|
-
event.id ||
|
|
978
|
-
`perf-${Date.now()}-${Math.random().toString(36).substring(2, 6)}`,
|
|
979
|
-
timestamp: event.timestamp || Date.now(),
|
|
980
|
-
source: event.source || getCallerSourceFile(),
|
|
981
|
-
...event,
|
|
982
|
-
};
|
|
983
|
-
globalPerformanceEvents.unshift(fullEvent);
|
|
984
|
-
if (globalPerformanceEvents.length > maxPerformanceEventsLimit) {
|
|
985
|
-
globalPerformanceEvents.length = maxPerformanceEventsLimit;
|
|
986
|
-
}
|
|
987
|
-
performanceListeners.forEach(listener => {
|
|
988
|
-
try {
|
|
989
|
-
listener([...globalPerformanceEvents]);
|
|
990
|
-
} catch {}
|
|
991
|
-
});
|
|
992
|
-
return fullEvent;
|
|
993
|
-
};
|
|
994
|
-
|
|
995
|
-
export const clearPerformanceEvents = () => {
|
|
996
|
-
globalPerformanceEvents.length = 0;
|
|
997
|
-
performanceListeners.forEach(listener => {
|
|
998
|
-
try {
|
|
999
|
-
listener([]);
|
|
1000
|
-
} catch {}
|
|
1001
|
-
});
|
|
1002
|
-
};
|
|
1003
|
-
|
|
1004
|
-
export const subscribePerformanceEvents = (
|
|
1005
|
-
listener: (events: PerformanceEvent[]) => void,
|
|
1006
|
-
) => {
|
|
1007
|
-
performanceListeners.add(listener);
|
|
1008
|
-
listener([...globalPerformanceEvents]);
|
|
1009
|
-
return () => {
|
|
1010
|
-
performanceListeners.delete(listener);
|
|
1011
|
-
};
|
|
1012
|
-
};
|
|
1013
|
-
|
|
1014
|
-
export const getPerformanceEvents = () => [...globalPerformanceEvents];
|