-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove metrics #479
Remove metrics #479
Changes from 2 commits
a33228a
df5d924
a3d0a9b
b7645d9
f1d5505
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import * as Logger from './Logger'; | |
import cache from './OnyxCache'; | ||
import * as Str from './Str'; | ||
import createDeferredTask from './createDeferredTask'; | ||
import * as PerformanceUtils from './metrics/PerformanceUtils'; | ||
import * as PerformanceUtils from './PerformanceUtils'; | ||
import Storage from './storage'; | ||
import utils from './utils'; | ||
import unstable_batchedUpdates from './batch'; | ||
|
@@ -1554,21 +1554,7 @@ function setMemoryOnlyKeys(keyList) { | |
* }, | ||
* }); | ||
*/ | ||
function init({ | ||
keys = {}, | ||
initialKeyStates = {}, | ||
safeEvictionKeys = [], | ||
maxCachedKeysCount = 1000, | ||
captureMetrics = false, | ||
shouldSyncMultipleInstances = Boolean(global.localStorage), | ||
debugSetState = false, | ||
} = {}) { | ||
if (captureMetrics) { | ||
// The code here is only bundled and applied when the captureMetrics is set | ||
// eslint-disable-next-line no-use-before-define | ||
applyDecorators(); | ||
} | ||
|
||
function init({keys = {}, initialKeyStates = {}, safeEvictionKeys = [], maxCachedKeysCount = 1000, shouldSyncMultipleInstances = Boolean(global.localStorage), debugSetState = false} = {}) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nab: shouldn't it be formatted like earlier? I think it was more readable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's how prettier formatted it after removing one parameter 😅 |
||
if (debugSetState) { | ||
PerformanceUtils.setShouldDebugSetState(true); | ||
} | ||
|
@@ -1630,42 +1616,4 @@ const Onyx = { | |
hasPendingMergeForKey, | ||
}; | ||
|
||
/** | ||
* Apply calls statistic decorators to benchmark Onyx | ||
* | ||
* @private | ||
*/ | ||
function applyDecorators() { | ||
// We're requiring the script dynamically here so that it's only evaluated when decorators are used | ||
const decorate = require('./metrics'); | ||
|
||
// Re-assign with decorated functions | ||
/* eslint-disable no-func-assign */ | ||
get = decorate.decorateWithMetrics(get, 'Onyx:get'); | ||
set = decorate.decorateWithMetrics(set, 'Onyx:set'); | ||
multiSet = decorate.decorateWithMetrics(multiSet, 'Onyx:multiSet'); | ||
clear = decorate.decorateWithMetrics(clear, 'Onyx:clear'); | ||
merge = decorate.decorateWithMetrics(merge, 'Onyx:merge'); | ||
mergeCollection = decorate.decorateWithMetrics(mergeCollection, 'Onyx:mergeCollection'); | ||
getAllKeys = decorate.decorateWithMetrics(getAllKeys, 'Onyx:getAllKeys'); | ||
initializeWithDefaultKeyStates = decorate.decorateWithMetrics(initializeWithDefaultKeyStates, 'Onyx:defaults'); | ||
update = decorate.decorateWithMetrics(update, 'Onyx:update'); | ||
/* eslint-enable */ | ||
|
||
// Re-expose decorated methods | ||
/* eslint-disable rulesdir/prefer-actions-set-data */ | ||
Onyx.set = set; | ||
Onyx.multiSet = multiSet; | ||
Onyx.clear = clear; | ||
Onyx.merge = merge; | ||
Onyx.mergeCollection = mergeCollection; | ||
Onyx.update = update; | ||
/* eslint-enable */ | ||
|
||
// Expose stats methods on Onyx | ||
Onyx.getMetrics = decorate.getMetrics; | ||
Onyx.resetMetrics = decorate.resetMetrics; | ||
Onyx.printMetrics = decorate.printMetrics; | ||
} | ||
|
||
export default Onyx; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import lodashTransform from 'lodash/transform'; | ||
import {deepEqual} from 'fast-equals'; | ||
|
||
type UnknownObject = Record<string, unknown>; | ||
|
||
type LogParams = { | ||
keyThatChanged?: string; | ||
difference?: unknown; | ||
previousValue?: unknown; | ||
newValue?: unknown; | ||
}; | ||
|
||
type Mapping = Record<string, unknown> & { | ||
key: string; | ||
displayName: string; | ||
}; | ||
|
||
let debugSetState = false; | ||
|
||
function setShouldDebugSetState(debug: boolean) { | ||
debugSetState = debug; | ||
} | ||
|
||
/** | ||
* Deep diff between two objects. Useful for figuring out what changed about an object from one render to the next so | ||
* that state and props updates can be optimized. | ||
*/ | ||
function diffObject<TObject extends UnknownObject, TBase extends UnknownObject>(object: TObject, base: TBase): UnknownObject { | ||
return lodashTransform(object, (result: UnknownObject, value, key) => { | ||
if (deepEqual(value, base[key])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You changed the method here, please make sure it works correctly |
||
return; | ||
} | ||
|
||
if (typeof value === 'object' && typeof base[key] === 'object') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was worried that |
||
// eslint-disable-next-line no-param-reassign | ||
result[key] = diffObject(value as UnknownObject, base[key] as UnknownObject); | ||
} else { | ||
// eslint-disable-next-line no-param-reassign | ||
result[key] = value; | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Provide insights into why a setState() call occurred by diffing the before and after values. | ||
*/ | ||
function logSetStateCall(mapping: Mapping, previousValue: unknown, newValue: unknown, caller: string, keyThatChanged: string) { | ||
if (!debugSetState) { | ||
return; | ||
} | ||
|
||
const logParams: LogParams = {}; | ||
if (keyThatChanged) { | ||
logParams.keyThatChanged = keyThatChanged; | ||
} | ||
if (newValue && previousValue && typeof newValue === 'object' && typeof previousValue === 'object') { | ||
logParams.difference = diffObject(previousValue as UnknownObject, newValue as UnknownObject); | ||
} else { | ||
logParams.previousValue = previousValue; | ||
logParams.newValue = newValue; | ||
} | ||
|
||
console.debug(`[Onyx-Debug] ${mapping.displayName} setState() called. Subscribed to key '${mapping.key}' (${caller})`, logParams); | ||
} | ||
|
||
export {logSetStateCall, setShouldDebugSetState}; |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure the changes here are reflected in
Onyx.d.ts
too!