mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
bc56f66b8d
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36314 ## Changelog: [Internal] - Added support for W3C Performance API extension (Performance,getEntries*) See [here for the details](https://www.w3.org/TR/performance-timeline/#extensions-to-the-performance-interface). This only supports `mark` and `measure` performance entry types (not `events`, as those are not supported by browsers either, they recommend using the `PerformanceObserver` API instead). From the implementation perspective, we already maintained persistent buffer for `mark` entry types, which was required in order to look up measures. The buffer is circular, limited to 1K entries by default. I basically mimic the same behavior for `measure` entry types as well, since it's the simplest way of doing it at this point, If we happen to want adding some other entry types that would be available via `Performance.getEntries*` API in the future, we may want to iterate on the internal data structures representation inside `PerformanceEntryReporter`, but for now I believe this approach should work just fine, and whatever changes we may want to do will be purely internal implementation detail. Reviewed By: rubennorte Differential Revision: D43625488 fbshipit-source-id: dd315b3f8488e910749a8e2a4158246e94d76f99
57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict
|
|
* @format
|
|
*/
|
|
|
|
import type {TurboModule} from '../TurboModule/RCTExport';
|
|
|
|
import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';
|
|
|
|
export type RawPerformanceEntryType = number;
|
|
|
|
export type RawPerformanceEntry = {|
|
|
name: string,
|
|
entryType: RawPerformanceEntryType,
|
|
startTime: number,
|
|
duration: number,
|
|
// For "event" entries only:
|
|
processingStart?: number,
|
|
processingEnd?: number,
|
|
interactionId?: number,
|
|
|};
|
|
|
|
export type GetPendingEntriesResult = {|
|
|
entries: $ReadOnlyArray<RawPerformanceEntry>,
|
|
droppedEntriesCount: number,
|
|
|};
|
|
|
|
export interface Spec extends TurboModule {
|
|
+startReporting: (entryType: RawPerformanceEntryType) => void;
|
|
+stopReporting: (entryType: RawPerformanceEntryType) => void;
|
|
+popPendingEntries: () => GetPendingEntriesResult;
|
|
+setOnPerformanceEntryCallback: (callback?: () => void) => void;
|
|
+logRawEntry: (entry: RawPerformanceEntry) => void;
|
|
+getEventCounts: () => $ReadOnlyArray<[string, number]>;
|
|
+setDurationThreshold: (
|
|
entryType: RawPerformanceEntryType,
|
|
durationThreshold: number,
|
|
) => void;
|
|
+clearEntries: (
|
|
entryType: RawPerformanceEntryType,
|
|
entryName?: string,
|
|
) => void;
|
|
+getEntries: (
|
|
entryType?: RawPerformanceEntryType,
|
|
entryName?: string,
|
|
) => $ReadOnlyArray<RawPerformanceEntry>;
|
|
}
|
|
|
|
export default (TurboModuleRegistry.get<Spec>(
|
|
'NativePerformanceObserverCxx',
|
|
): ?Spec);
|