Commit d19efcf
Incorporate perf_hooks into main Node.js lib defs and align with v24 (#55058)
Summary:
Pull Request resolved: #55058
This is an AI-assisted change to consolidate Metro's separate `perf_hooks.js` file into the main Node.js library definitions and align with Node.js v24 (effectively v22) standards.
**Consolidation Changes:**
1. **Incorporated Separate File** - Removed duplication
- Moved definitions from `metro/flow-typed/perf_hooks.js` into main `node.js` files
- Deleted the separate perf_hooks.js file (no longer needed)
- Both Metro and React Native now use unified definitions
- Positioned alphabetically between 'path' and 'punycode' modules
**Enhanced Histogram Types:**
2. **Complete Histogram Interface** - Added missing bigint support (v17.4.0)
- `count` and `countBigInt` - Total sample count
- `exceeds` and `exceedsBigInt` - Samples exceeding 1-hour threshold
- `max` and `maxBigInt` - Maximum recorded value
- `min` and `minBigInt` - Minimum recorded value
- `percentile()` and `percentileBigInt()` - Get value at percentile
- `percentiles` and `percentilesBigInt` - Map of percentile distributions
- https://nodejs.org/api/perf_hooks.html#class-histogram
3. **RecordableHistogram Interface** - Custom histogram creation (v15.9.0, v14.18.0)
- `record(val)` - Record a value in the histogram
- `recordDelta()` - Record time delta since last call
- Used with `createHistogram()` for custom performance tracking
- https://nodejs.org/api/perf_hooks.html#class-recordablehistogram
**Enhanced Performance Entry Classes:**
4. **PerformanceNodeTiming Class** - Complete Node.js lifecycle timing
- Renamed from PerformanceNodeEntry for accuracy
- `bootstrapComplete` - Bootstrap completion timestamp
- `environment` - Environment initialization timestamp
- `idleTime` - Event loop idle time (v14.10.0)
- `loopStart`, `loopExit` - Event loop lifecycle timestamps
- `nodeStart` - Process initialization timestamp
- `v8Start` - V8 platform initialization timestamp
- https://nodejs.org/api/perf_hooks.html#class-performancenodetiming
5. **PerformanceResourceTiming Class** - Network timing details (v18.2.0, v16.17.0)
- Complete Web Performance API compatibility
- Timing properties: `workerStart`, `redirectStart/End`, `fetchStart`, `domainLookupStart/End`, `connectStart/End`, `secureConnectionStart`, `requestStart`, `responseEnd`
- Size properties: `transferSize`, `encodedBodySize`, `decodedBodySize`
- Used for detailed network request profiling
- https://nodejs.org/api/perf_hooks.html#class-performanceresourcetiming
6. **PerformanceMark and PerformanceMeasure** - Enhanced type safety
- Generic type parameter `<T>` for custom detail objects
- `PerformanceMark<T>` has `duration: 0` (point in time)
- `PerformanceMeasure<T>` has variable duration (time span)
- Both support custom `detail` property for user data
**New Functions:**
7. **createHistogram()** - Custom histogram creation (v15.9.0, v14.18.0)
- Options: `lowest`, `highest` (number | bigint), `figures` (precision)
- Returns `RecordableHistogram` for custom performance metrics
- Enables fine-grained performance measurement
- https://nodejs.org/api/perf_hooks.html#perf_hookscreatehistogramoptions
**Performance Object Enhancements:**
8. **Enhanced Performance Class**
- `clearResourceTimings(name?)` - Clear specific resource timings
- `timerify()` enhanced with histogram option: `Readonly<{histogram?: RecordableHistogram}>`
- All timing methods return proper typed instances
9. **GC Constants Export** - Garbage collection monitoring
- `constants.NODE_PERFORMANCE_GC_MAJOR` - Major GC
- `constants.NODE_PERFORMANCE_GC_MINOR` - Minor/scavenge GC
- `constants.NODE_PERFORMANCE_GC_INCREMENTAL` - Incremental marking GC
- `constants.NODE_PERFORMANCE_GC_WEAKCB` - Weak callback processing
- GC flags: `FLAGS_NO`, `FLAGS_CONSTRUCT_RETAINED`, `FLAGS_FORCED`, `FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING`, `FLAGS_ALL_AVAILABLE_GARBAGE`, `FLAGS_ALL_EXTERNAL_MEMORY`, `FLAGS_SCHEDULE_IDLE`
- https://nodejs.org/api/perf_hooks.html#perf_hooksconstants
**Modern Flow Type Improvements:**
10. **Readonly Input Types** - Applied consistently
- `PerformanceMarkOptions<T>`: `Readonly<{detail?, startTime?}>`
- `PerformanceMeasureOptions<T>`: `Readonly<{detail?, duration?, end?, start?}>`
- `PerformanceObserver.observe()`: `Readonly<{entryTypes?, type?, buffered?}>`
- `monitorEventLoopDelay()`: `Readonly<{resolution?}>`
- `createHistogram()`: `Readonly<{lowest?, highest?, figures?}>`
- `timerify()` histogram option: `Readonly<{histogram?}>`
11. **Entry Type Safety** - Proper union type
- `perf_hooks$EntryType`: `'function' | 'gc' | 'http' | 'http2' | 'mark' | 'measure' | 'navigation' | 'node' | 'resource'`
- Used throughout for type-safe entry type filtering
12. **Export Type Aliases** - Better developer experience
- All classes and interfaces exported as both types and values
- Consistent `perf_hooks$` prefix for internal types
- Clean module exports without duplication
**Observer Enhancements:**
13. **PerformanceObserver.observe()** - Flexible options (v16.0.0)
- Support both `type` (single) and `entryTypes` (multiple) options
- `buffered` option to include past entries
- `takeRecords()` method for manual retrieval
**References:**
- Node.js perf_hooks module docs: https://nodejs.org/api/perf_hooks.html
- Web Performance API spec: https://w3c.github.io/performance-timeline/
- User Timing spec: https://w3c.github.io/user-timing/
- Resource Timing spec: https://w3c.github.io/resource-timing/
Changelog: [Internal]
---
> Generated by [Confucius Code Assist (CCA)](https://www.internalfb.com/wiki/Confucius/Analect/Shared_Analects/Confucius_Code_Assist_(CCA)/)
[Confucius Session](https://www.internalfb.com/confucius?host=devvm45708.cln0.facebook.com&port=8086&tab=Chat&session_id=1a3aa26e-e5a9-11f0-8d47-71a4a90f0494&entry_name=Code+Assist), [Trace](https://www.internalfb.com/confucius?session_id=1a3aa26e-e5a9-11f0-8d47-71a4a90f0494&tab=Trace)
Reviewed By: vzaidman
Differential Revision: D89944490
fbshipit-source-id: 28e89ee27ce0150db063d6c3757defc3bba512c01 parent dcfe7f5 commit d19efcf
1 file changed
Lines changed: 200 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2863 | 2863 | | |
2864 | 2864 | | |
2865 | 2865 | | |
| 2866 | + | |
| 2867 | + | |
| 2868 | + | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
| 2890 | + | |
| 2891 | + | |
| 2892 | + | |
| 2893 | + | |
| 2894 | + | |
| 2895 | + | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
| 2902 | + | |
| 2903 | + | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
| 2912 | + | |
| 2913 | + | |
| 2914 | + | |
| 2915 | + | |
| 2916 | + | |
| 2917 | + | |
| 2918 | + | |
| 2919 | + | |
| 2920 | + | |
| 2921 | + | |
| 2922 | + | |
| 2923 | + | |
| 2924 | + | |
| 2925 | + | |
| 2926 | + | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
| 2930 | + | |
| 2931 | + | |
| 2932 | + | |
| 2933 | + | |
| 2934 | + | |
| 2935 | + | |
| 2936 | + | |
| 2937 | + | |
| 2938 | + | |
| 2939 | + | |
| 2940 | + | |
| 2941 | + | |
| 2942 | + | |
| 2943 | + | |
| 2944 | + | |
| 2945 | + | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
| 2949 | + | |
| 2950 | + | |
| 2951 | + | |
| 2952 | + | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + | |
| 2959 | + | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
| 2992 | + | |
| 2993 | + | |
| 2994 | + | |
| 2995 | + | |
| 2996 | + | |
| 2997 | + | |
| 2998 | + | |
| 2999 | + | |
| 3000 | + | |
| 3001 | + | |
| 3002 | + | |
| 3003 | + | |
| 3004 | + | |
| 3005 | + | |
| 3006 | + | |
| 3007 | + | |
| 3008 | + | |
| 3009 | + | |
| 3010 | + | |
| 3011 | + | |
| 3012 | + | |
| 3013 | + | |
| 3014 | + | |
| 3015 | + | |
| 3016 | + | |
| 3017 | + | |
| 3018 | + | |
| 3019 | + | |
| 3020 | + | |
| 3021 | + | |
| 3022 | + | |
| 3023 | + | |
| 3024 | + | |
| 3025 | + | |
| 3026 | + | |
| 3027 | + | |
| 3028 | + | |
| 3029 | + | |
| 3030 | + | |
| 3031 | + | |
| 3032 | + | |
| 3033 | + | |
| 3034 | + | |
| 3035 | + | |
| 3036 | + | |
| 3037 | + | |
| 3038 | + | |
| 3039 | + | |
| 3040 | + | |
| 3041 | + | |
| 3042 | + | |
| 3043 | + | |
| 3044 | + | |
| 3045 | + | |
| 3046 | + | |
| 3047 | + | |
| 3048 | + | |
| 3049 | + | |
| 3050 | + | |
| 3051 | + | |
| 3052 | + | |
| 3053 | + | |
| 3054 | + | |
| 3055 | + | |
| 3056 | + | |
| 3057 | + | |
| 3058 | + | |
| 3059 | + | |
| 3060 | + | |
| 3061 | + | |
2866 | 3062 | | |
2867 | 3063 | | |
2868 | 3064 | | |
| |||
4849 | 5045 | | |
4850 | 5046 | | |
4851 | 5047 | | |
| 5048 | + | |
| 5049 | + | |
| 5050 | + | |
| 5051 | + | |
4852 | 5052 | | |
4853 | 5053 | | |
4854 | 5054 | | |
| |||
0 commit comments