mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-21 22:47:49 +00:00
Use native structuredClone instead of _.cloneDeep
Memory tests have shown performance improvements to using the native method. Change-type: patch Signed-off-by: Christina Ying Wang <christina@balena.io>
This commit is contained in:
parent
07a2a34f51
commit
06d4775178
@ -40,8 +40,8 @@
|
||||
"systeminformation": "^5.6.10"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.17.0",
|
||||
"npm": ">=8.15.0"
|
||||
"node": ">=18.18.0",
|
||||
"npm": ">=9.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@balena/contrato": "^0.6.0",
|
||||
|
@ -528,7 +528,7 @@ export const initialized = _.once(async () => {
|
||||
}
|
||||
|
||||
const baseUrl = url.resolve(apiEndpoint, '/v6/');
|
||||
const passthrough = _.cloneDeep(await request.getRequestOptions());
|
||||
const passthrough = structuredClone(await request.getRequestOptions());
|
||||
passthrough.headers = passthrough.headers != null ? passthrough.headers : {};
|
||||
passthrough.headers.Authorization = `Bearer ${currentApiKey}`;
|
||||
balenaApi = new PinejsClientRequest({
|
||||
|
@ -546,7 +546,7 @@ export async function setTarget(
|
||||
// filter those out and add the target state to the database
|
||||
const contractViolators: { [appName: string]: string[] } = {};
|
||||
const fulfilledContracts = validateTargetContracts(apps);
|
||||
const filteredApps = _.cloneDeep(apps);
|
||||
const filteredApps = structuredClone(apps);
|
||||
_.each(
|
||||
fulfilledContracts,
|
||||
(
|
||||
|
@ -261,7 +261,7 @@ export class Network {
|
||||
// default or generated values)
|
||||
let configToCompare = this.config;
|
||||
if (network.config.ipam.config.length === 0) {
|
||||
configToCompare = _.cloneDeep(this.config);
|
||||
configToCompare = structuredClone(this.config);
|
||||
configToCompare.ipam.config = [];
|
||||
}
|
||||
|
||||
@ -270,7 +270,7 @@ export class Network {
|
||||
// Any ipam config will be included in the network, but not applied
|
||||
// in the host's networking layer.
|
||||
if (network.config.configOnly) {
|
||||
configToCompare = _.cloneDeep(this.config);
|
||||
configToCompare = structuredClone(this.config);
|
||||
configToCompare.driver = network.config.driver;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ export function camelCaseConfig(
|
||||
// Networks can either be an object or array, but given _.isObject
|
||||
// returns true for an array, we check the other way
|
||||
if (!_.isArray(config.networks)) {
|
||||
const networksTmp = _.cloneDeep(config.networks);
|
||||
const networksTmp = structuredClone(config.networks);
|
||||
_.each(networksTmp, (v, k) => {
|
||||
config.networks[k] = _.mapKeys(v, (_v, key) => _.camelCase(key));
|
||||
});
|
||||
|
@ -389,7 +389,7 @@ export function bootConfigChangeRequired(
|
||||
const SPECIAL_CASE = 'configuration'; // ODMDATA Mode for TX2 devices
|
||||
if (!(SPECIAL_CASE in targetBootConfig)) {
|
||||
// Create a copy to modify
|
||||
const targetCopy = _.cloneDeep(targetBootConfig);
|
||||
const targetCopy = structuredClone(targetBootConfig);
|
||||
// Add current value to simulate if the value was set in the cloud on provision
|
||||
targetCopy[SPECIAL_CASE] = currentBootConfig[SPECIAL_CASE];
|
||||
if (_.isEqual(targetCopy, currentBootConfig)) {
|
||||
|
@ -64,7 +64,7 @@ const emitTargetState = (
|
||||
// CachedResponse has not been emitted before so emit as an update
|
||||
emitter.emit(
|
||||
'target-state-update',
|
||||
_.cloneDeep(cachedResponse.body),
|
||||
structuredClone(cachedResponse.body),
|
||||
force,
|
||||
isFromApi,
|
||||
);
|
||||
@ -201,7 +201,7 @@ const poll = async (
|
||||
*/
|
||||
export const get = async (): Promise<TargetState> => {
|
||||
await update();
|
||||
return _.cloneDeep(cache.body);
|
||||
return structuredClone(cache.body);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@ export async function track(
|
||||
properties = { error: properties };
|
||||
}
|
||||
|
||||
properties = _.cloneDeep(properties);
|
||||
properties = structuredClone(properties);
|
||||
if (properties.error instanceof Error) {
|
||||
// Format the error for printing, to avoid display as { }
|
||||
properties.error = {
|
||||
|
Loading…
Reference in New Issue
Block a user