launchpad: Improve sortedObject performance for large objects

This commit is contained in:
willclarktech 2021-01-05 13:05:43 +00:00
parent ed11f30707
commit 5358e9c4f8
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7

View File

@ -13,13 +13,11 @@ function sortedObject(obj: any): any {
return obj.map(sortedObject);
}
const sortedKeys = Object.keys(obj).sort();
const result = sortedKeys.reduce(
(accumulator, key) => ({
...accumulator,
[key]: sortedObject(obj[key]),
}),
{},
);
const result: Record<string, any> = {};
// NOTE: Use forEach instead of reduce for performance with large objects eg Wasm code
sortedKeys.forEach((key) => {
result[key] = sortedObject(obj[key]);
});
return result;
}