-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(): Remove over-protective cloneDeep from fromObject (#9621)
- Loading branch information
Showing
21 changed files
with
208 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ coverage/ | |
test/ | ||
test* | ||
e2e/ | ||
src/benchmarks | ||
.DS_Store | ||
.codesandbox/ | ||
.devcontainer/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* eslint-disable no-restricted-syntax */ | ||
import { cloneStyles } from '../../dist/src/util/internals/cloneStyles.mjs'; | ||
import { cloneDeep } from '../../dist/src/util/internals/cloneDeep.mjs'; | ||
|
||
const style = { | ||
fill: 'blue', | ||
stroke: 'red', | ||
strokeWidth: 8, | ||
fontSize: 44, | ||
fontFamily: 'Roboto', | ||
fontWeight: 'bold', | ||
fontStyle: 'italic', | ||
textBackgroundColor: 'green', | ||
deltaY: -5, | ||
overline: true, | ||
underline: false, | ||
linethrough: true, | ||
}; | ||
|
||
const testObject = { | ||
0: { | ||
0: style, | ||
6: { ...style, fill: 'green' }, | ||
}, | ||
1: { | ||
0: { ...style }, | ||
3: { ...style }, | ||
}, | ||
2: { | ||
0: { ...style }, | ||
3: { ...style }, | ||
}, | ||
}; | ||
|
||
const benchmark = async (callback) => { | ||
const start = Date.now(); | ||
await callback(); | ||
return Date.now() - start; | ||
}; | ||
|
||
const size = 100_000; | ||
|
||
const cloneDeepTest = await benchmark(async () => { | ||
for (let i = 0; i < size; i++) { | ||
cloneDeep(testObject); | ||
} | ||
}); | ||
|
||
const cloneStylesTest = await benchmark(async () => { | ||
for (let i = 0; i < size; i++) { | ||
await cloneStyles(testObject); | ||
} | ||
}); | ||
|
||
console.log({ | ||
cloneDeepTest, | ||
cloneStylesTest, | ||
}); | ||
|
||
/** | ||
* results on a m1pro | ||
* { cloneDeepTest: 742, cloneStylesTest: 364 } | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
/** | ||
* @deprecated Using a generic JSON parse/stringify on random object may bring to slow perf issues, | ||
* if needed to clone complicated data structures use a dedicated clone logic | ||
* @param object | ||
* @returns | ||
*/ | ||
export const cloneDeep = <T extends object>(object: T): T => | ||
JSON.parse(JSON.stringify(object)); |
Oops, something went wrong.