Skip to content

Commit b5a5132

Browse files
Merge pull request #762 from callstack-internal/chore/remove-unusued-metrics-system
chore: Remove unusued performance metrics system
2 parents 5260a66 + 796ce01 commit b5a5132

13 files changed

Lines changed: 3 additions & 325 deletions

File tree

README.md

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -351,59 +351,6 @@ const ReportActionsView = ({reportID, isActiveReport}) => {
351351
export default ReportActionsView;
352352
```
353353

354-
# Benchmarks
355-
356-
Provide the `captureMetrics` boolean flag to `Onyx.init` to capture call statistics
357-
358-
```js
359-
Onyx.init({
360-
keys: ONYXKEYS,
361-
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
362-
captureMetrics: Config.BENCHMARK_ONYX,
363-
});
364-
```
365-
366-
At any point you can get the collected statistics using `Onyx.getMetrics()`.
367-
This will return an object containing `totalTime`, `averageTime` and `summaries`.
368-
`summaries` is a collection of statistics for each method it contains data about:
369-
- method name
370-
- total, max, min, average times for this method calls
371-
- calls - a list of individual calls with each having: start time; end time; call duration; call arguments
372-
- start/end times are relative to application launch time - 0.00 being exactly at launch
373-
374-
If you wish to reset the metrics and start over use `Onyx.resetMetrics()`
375-
376-
Finally, there's a `Onyx.printMetrics()` method which prints human statistics information on the dev console. You can use this method during debugging. For example add an `Onyx.printMetrics()` line somewhere in code or call it through the dev console. It supports 3 popular formats *MD* - human friendly markdown, *CSV* and *JSON*. The default is MD if you want to print another format call `Onyx.printMetrics({ format: 'csv' })` or
377-
`Onyx.printMetrics({ format: 'json' })`.
378-
379-
Sample output of `Onyx.printMetrics()`
380-
381-
```
382-
### Onyx Benchmark
383-
- Total: 1.5min
384-
- Last call finished at: 12.55sec
385-
386-
| method | total time spent | max | min | avg | time last call completed | calls made |
387-
|-----------------|-----------------:|----------:|---------:|----------:|-------------------------:|-----------:|
388-
| Onyx:getAllKeys | 1.2min | 2.16sec | 0.159ms | 782.230ms | 12.55sec | 90 |
389-
| Onyx:merge | 4.73sec | 2.00sec | 74.412ms | 591.642ms | 10.24sec | 8 |
390-
| Onyx:set | 3.90sec | 846.760ms | 43.663ms | 433.056ms | 7.47sec | 9 |
391-
| Onyx:get | 8.87sec | 2.00sec | 0.063ms | 61.998ms | 10.24sec | 143 |
392-
393-
394-
| Onyx:set |
395-
|---------------------------------------------------------------|
396-
| start time | end time | duration | args |
397-
|-----------:|----------:|----------:|--------------------------|
398-
| 291.042ms | 553.079ms | 262.037ms | session, [object Object] |
399-
| 293.719ms | 553.316ms | 259.597ms | account, [object Object] |
400-
| 294.541ms | 553.651ms | 259.109ms | network, [object Object] |
401-
| 365.378ms | 554.246ms | 188.867ms | iou, [object Object] |
402-
| 1.08sec | 2.20sec | 1.12sec | network, [object Object] |
403-
| 1.08sec | 2.20sec | 1.12sec | iou, [object Object] |
404-
| 1.17sec | 2.20sec | 1.03sec | currentURL, / |
405-
```
406-
407354
# Debug mode
408355

409356
It can be useful to log why Onyx is calling `setState()` on a particular React component so that we can understand which key changed, what changed about the value, and the connected component that ultimately rendered as a result. When used correctly this can help isolate problem areas and unnecessary renders in the code. To enable this feature, pass `debugSetState: true` to the config and grep JS console logs for `[Onyx-Debug]`.

lib/GlobalSettings.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

lib/Onyx.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import OnyxKeys from './OnyxKeys';
2727
import logMessages from './logMessages';
2828
import type {Connection} from './OnyxConnectionManager';
2929
import connectionManager from './OnyxConnectionManager';
30-
import * as GlobalSettings from './GlobalSettings';
31-
import decorateWithMetrics from './metrics';
3230
import OnyxMerge from './OnyxMerge';
3331

3432
/** Initialize the store with actions and listening for storage events */
@@ -38,17 +36,11 @@ function init({
3836
evictableKeys = [],
3937
maxCachedKeysCount = 1000,
4038
shouldSyncMultipleInstances = !!global.localStorage,
41-
enablePerformanceMetrics = false,
4239
enableDevTools = true,
4340
skippableCollectionMemberIDs = [],
4441
ramOnlyKeys = [],
4542
snapshotMergeKeys = [],
4643
}: InitOptions): void {
47-
if (enablePerformanceMetrics) {
48-
GlobalSettings.setPerformanceMetricsEnabled(true);
49-
applyDecorators();
50-
}
51-
5244
initDevTools(enableDevTools);
5345

5446
Storage.init();
@@ -605,25 +597,5 @@ const Onyx = {
605597
registerLogger: Logger.registerLogger,
606598
};
607599

608-
function applyDecorators() {
609-
// We are reassigning the functions directly so that internal function calls are also decorated
610-
// @ts-expect-error Reassign
611-
connect = decorateWithMetrics(connect, 'Onyx.connect');
612-
// @ts-expect-error Reassign
613-
connectWithoutView = decorateWithMetrics(connectWithoutView, 'Onyx.connectWithoutView');
614-
// @ts-expect-error Reassign
615-
set = decorateWithMetrics(set, 'Onyx.set');
616-
// @ts-expect-error Reassign
617-
multiSet = decorateWithMetrics(multiSet, 'Onyx.multiSet');
618-
// @ts-expect-error Reassign
619-
merge = decorateWithMetrics(merge, 'Onyx.merge');
620-
// @ts-expect-error Reassign
621-
mergeCollection = decorateWithMetrics(mergeCollection, 'Onyx.mergeCollection');
622-
// @ts-expect-error Reassign
623-
update = decorateWithMetrics(update, 'Onyx.update');
624-
// @ts-expect-error Reassign
625-
clear = decorateWithMetrics(clear, 'Onyx.clear');
626-
}
627-
628600
export default Onyx;
629601
export type {OnyxUpdate, ConnectOptions, SetOptions};

lib/OnyxUtils.ts

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ import type {FastMergeOptions, FastMergeResult} from './utils';
3636
import utils from './utils';
3737
import type {DeferredTask} from './createDeferredTask';
3838
import createDeferredTask from './createDeferredTask';
39-
import * as GlobalSettings from './GlobalSettings';
40-
import decorateWithMetrics from './metrics';
4139
import type {StorageKeyValuePair} from './storage/providers/types';
4240
import logMessages from './logMessages';
4341

@@ -1771,52 +1769,6 @@ const OnyxUtils = {
17711769
setCollectionWithRetry,
17721770
};
17731771

1774-
GlobalSettings.addGlobalSettingsChangeListener(({enablePerformanceMetrics}) => {
1775-
if (!enablePerformanceMetrics) {
1776-
return;
1777-
}
1778-
// We are reassigning the functions directly so that internal function calls are also decorated
1779-
1780-
// @ts-expect-error Reassign
1781-
initStoreValues = decorateWithMetrics(initStoreValues, 'OnyxUtils.initStoreValues');
1782-
// @ts-expect-error Complex type signature
1783-
get = decorateWithMetrics(get, 'OnyxUtils.get');
1784-
// @ts-expect-error Reassign
1785-
getAllKeys = decorateWithMetrics(getAllKeys, 'OnyxUtils.getAllKeys');
1786-
// @ts-expect-error Reassign
1787-
keysChanged = decorateWithMetrics(keysChanged, 'OnyxUtils.keysChanged');
1788-
// @ts-expect-error Reassign
1789-
keyChanged = decorateWithMetrics(keyChanged, 'OnyxUtils.keyChanged');
1790-
// @ts-expect-error Reassign
1791-
sendDataToConnection = decorateWithMetrics(sendDataToConnection, 'OnyxUtils.sendDataToConnection');
1792-
// @ts-expect-error Reassign
1793-
scheduleSubscriberUpdate = decorateWithMetrics(scheduleSubscriberUpdate, 'OnyxUtils.scheduleSubscriberUpdate');
1794-
// @ts-expect-error Reassign
1795-
scheduleNotifyCollectionSubscribers = decorateWithMetrics(scheduleNotifyCollectionSubscribers, 'OnyxUtils.scheduleNotifyCollectionSubscribers');
1796-
// @ts-expect-error Reassign
1797-
remove = decorateWithMetrics(remove, 'OnyxUtils.remove');
1798-
// @ts-expect-error Reassign
1799-
reportStorageQuota = decorateWithMetrics(reportStorageQuota, 'OnyxUtils.reportStorageQuota');
1800-
// @ts-expect-error Complex type signature
1801-
retryOperation = decorateWithMetrics(retryOperation, 'OnyxUtils.retryOperation');
1802-
// @ts-expect-error Reassign
1803-
broadcastUpdate = decorateWithMetrics(broadcastUpdate, 'OnyxUtils.broadcastUpdate');
1804-
// @ts-expect-error Reassign
1805-
initializeWithDefaultKeyStates = decorateWithMetrics(initializeWithDefaultKeyStates, 'OnyxUtils.initializeWithDefaultKeyStates');
1806-
// @ts-expect-error Complex type signature
1807-
multiGet = decorateWithMetrics(multiGet, 'OnyxUtils.multiGet');
1808-
// @ts-expect-error Reassign
1809-
tupleGet = decorateWithMetrics(tupleGet, 'OnyxUtils.tupleGet');
1810-
// @ts-expect-error Reassign
1811-
subscribeToKey = decorateWithMetrics(subscribeToKey, 'OnyxUtils.subscribeToKey');
1812-
// @ts-expect-error Reassign
1813-
setWithRetry = decorateWithMetrics(setWithRetry, 'OnyxUtils.setWithRetry');
1814-
// @ts-expect-error Reassign
1815-
multiSetWithRetry = decorateWithMetrics(multiSetWithRetry, 'OnyxUtils.multiSetWithRetry');
1816-
// @ts-expect-error Reassign
1817-
setCollectionWithRetry = decorateWithMetrics(setCollectionWithRetry, 'OnyxUtils.setCollectionWithRetry');
1818-
});
1819-
18201772
export type {OnyxMethod};
18211773
export default OnyxUtils;
18221774
export {clearOnyxUtilsInternals};

lib/dependencies/ModuleProxy.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

lib/dependencies/PerformanceProxy/index.native.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

lib/dependencies/PerformanceProxy/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

lib/metrics.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

lib/storage/index.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import PlatformStorage from './platforms';
44
import InstanceSync from './InstanceSync';
55
import MemoryOnlyProvider from './providers/MemoryOnlyProvider';
66
import type StorageProvider from './providers/types';
7-
import * as GlobalSettings from '../GlobalSettings';
8-
import decorateWithMetrics from '../metrics';
97

108
let provider = PlatformStorage as StorageProvider<unknown>;
119
let shouldKeepInstancesSync = false;
@@ -209,23 +207,4 @@ const storage: Storage = {
209207
},
210208
};
211209

212-
GlobalSettings.addGlobalSettingsChangeListener(({enablePerformanceMetrics}) => {
213-
if (!enablePerformanceMetrics) {
214-
return;
215-
}
216-
217-
// Apply decorators
218-
storage.getItem = decorateWithMetrics(storage.getItem, 'Storage.getItem');
219-
storage.multiGet = decorateWithMetrics(storage.multiGet, 'Storage.multiGet');
220-
storage.setItem = decorateWithMetrics(storage.setItem, 'Storage.setItem');
221-
storage.multiSet = decorateWithMetrics(storage.multiSet, 'Storage.multiSet');
222-
storage.mergeItem = decorateWithMetrics(storage.mergeItem, 'Storage.mergeItem');
223-
storage.multiMerge = decorateWithMetrics(storage.multiMerge, 'Storage.multiMerge');
224-
storage.removeItem = decorateWithMetrics(storage.removeItem, 'Storage.removeItem');
225-
storage.removeItems = decorateWithMetrics(storage.removeItems, 'Storage.removeItems');
226-
storage.clear = decorateWithMetrics(storage.clear, 'Storage.clear');
227-
storage.getAllKeys = decorateWithMetrics(storage.getAllKeys, 'Storage.getAllKeys');
228-
storage.getAll = decorateWithMetrics(storage.getAll, 'Storage.getAll');
229-
});
230-
231210
export default storage;

lib/types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,6 @@ type InitOptions = {
407407
*/
408408
shouldSyncMultipleInstances?: boolean;
409409

410-
/**
411-
* If enabled it will use the performance API to measure the time taken by Onyx operations.
412-
* @default false
413-
*/
414-
enablePerformanceMetrics?: boolean;
415-
416410
/**
417411
* If enabled, it will connect to Redux DevTools Extension for debugging.
418412
* This allows you to see all Onyx state changes in the Redux DevTools.

0 commit comments

Comments
 (0)