Skip to content
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

chore(): Remove over-protective cloneDeep from fromObject #9621

Merged
merged 13 commits into from
Aug 15, 2024

Conversation

asturur
Copy link
Member

@asturur asturur commented Jan 21, 2024

Description

We need to protect from unwanted references when restoring from data.
Today we deeply clone every object, and that is expensive ( measured on an app with 91 canvases it went from 480 to around 420 ms ) and overly protective.

In the case of Object._fromObject options ( renamed in serializedOptions ) is passing through the enliving process that already a shallow clone

Other deep level cloning are left to the single objects duty or single properties ( gradients, pattern, array ) but they need to be carefully inspected

This PR is a wip and will add more checks on data cloning later

Copy link

codesandbox bot commented Jan 21, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@asturur asturur changed the title WIP chore(): Remove over-protective cloneDeep from fromObject WIP - DRAFT chore(): Remove over-protective cloneDeep from fromObject Jan 21, 2024
color: colorStop.color,
offset: colorStop.offset,
opacity: colorStop.opacity,
}));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gradient should have a fromObject like Pattern

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

github-actions bot commented Jan 21, 2024

Build Stats

file / KB (diff) bundled minified
fabric 920.656 (+0.446) 307.017 (+0.219)

(enlivedMap) => {
const allOptions = { ...options, ...enlivedMap };
return enlivenObjectEnlivables<any>(serializedObjectOptions, options).then(
(enlivedObjectOptions) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enlivedObjectOptions is a shallow clone of object so we can delete or reassign properties freely.

{ extraParam, ...options }: Abortable & { extraParam?: string } = {}
): Promise<S> {
return enlivenObjectEnlivables<any>(cloneDeep(object), options).then(
(enlivedMap) => {
const allOptions = { ...options, ...enlivedMap };
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only other valuable here should be signal. not worth a full spread.

@asturur asturur marked this pull request as ready for review August 15, 2024 06:43
@asturur asturur changed the title WIP - DRAFT chore(): Remove over-protective cloneDeep from fromObject chore(): Remove over-protective cloneDeep from fromObject Aug 15, 2024
Copy link
Contributor

Coverage after merging fromObject-clone-cleanup into master will be

84.82%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
index.node.ts14.29%100%0%25%23, 26, 29, 41, 44, 47
extensions/aligning_guidelines/util
   basic.ts100%100%100%100%
src
   ClassRegistry.ts91.18%64.29%100%97.92%35, 56
   Collection.ts78.47%42.62%87.10%85.82%130, 138, 153, 155–157, 159, 169–170, 181, 197, 215, 217, 228, 243, 254, 265, 270, 279, 281, 286–287, 302, 304, 309–310, 329, 333–334, 338–344, 346–348, 350
   CommonMethods.ts91.43%71.43%100%96%50, 52
   Intersection.ts85.25%48.91%100%97.30%184–188, 190, 228, 237, 239, 289, 297, 297
   Observable.ts80.63%53.49%93.75%87.88%144, 153, 156, 168, 170, 175, 68–70, 72, 76, 80, 84–85, 87–91
   Point.ts90.53%62%100%93.90%104, 117, 148, 157, 179, 197, 206, 216, 225, 236–239, 259, 285, 297, 328, 341, 349, 359, 95
   Shadow.ts89.21%78.26%100%90%140, 143, 145–150, 159, 196, 199, 206, 223–230, 234–235
   cache.ts84.88%45.45%100%90.14%57, 59, 71–72, 74–77
   config.ts87.73%55%66.67%94.03%132, 134–137, 139, 142–143, 147, 152
   constants.ts100%100%100%100%
src/LayoutManager
   ActiveSelectionLayoutManager.ts91.67%69.23%85.71%100%43
   LayoutManager.ts90.75%65.48%76.92%99.31%279, 344, 355
   constants.ts100%100%100%100%
   index.ts48.57%37.50%80%66.67%1, 1, 1–2, 2, 2–3, 3, 3–4, 4, 4–5, 5, 5, 5–6
   types.ts100%100%100%100%
src/LayoutManager/LayoutStrategies
   ClipPathLayout.ts75%56.25%100%78.95%39, 41–44, 46–48, 66–69
   FitContentLayout.ts100%100%100%100%
   FixedLayout.ts85.71%20%100%100%23, 23
   LayoutStrategy.ts87.60%57.14%100%96.51%46, 54, 73, 73, 75
   utils.ts72.58%50%100%78.72%29–32, 34–35, 40–44
src/Pattern
   Pattern.ts67.50%88.57%80%63.08%105–107, 114, 118–119, 119–122, 130–138, 140–141, 143, 153–164, 174, 176–181, 183–188, 190–199, 203–206, 209–210, 212–214, 216–218, 218–221, 33, 37
src/brushes
   BaseBrush.ts89.33%91.67%100%88.55%110, 115, 124–125, 130, 135, 143, 146, 155–160, 99
   CircleBrush.ts52.10%12.50%12.50%58.25%100–108, 108–118, 122, 130–139, 55, 67, 69, 76, 76, 78–79, 79, 83, 85–86, 92–98
   PatternBrush.ts97.06%87.50%100%100%21
   PencilBrush.ts91.06%82.35%100%93.81%122–123, 152, 152–154, 176, 176, 276, 280, 285–286, 68–69, 84–85
   SprayBrush.ts0%0%0%0%107, 107, 107, 107, 107–108, 110–111, 118–119, 121, 123–127, 136, 140–141, 141, 148, 148, 148–151, 153–156, 160–161, 163, 165–168, 17, 171, 178–179, 18, 181, 183–184, 186, 193–194, 196–197, 20, 200, 200, 207, 207, 21, 211, 22, 22, 22–24, 28, 32, 39, 46, 53, 60, 67, 84–86, 94–96, 98–99
src/canvas
   Canvas.ts75.75%41.11%92.86%85.03%1000, 1005, 1009, 1013–1014, 1019, 1064–1069, 1127, 1131, 1138, 1141, 1204–1208, 1287–1291, 1318, 1335, 1381–1398, 1404–1409, 1412–1413, 1415, 1419, 1421–1422, 1424–1426, 1430, 1432, 1434–1436, 1439–1444, 1447–1449, 1452, 1454, 1468, 1475, 1477–1488, 1490–1493, 1493–1494, 1496–1497, 1501–1502, 1505–1506, 1509–1511, 1514, 329, 354, 370, 389, 444, 560–564, 567–568, 570, 580, 583–584, 586, 589–591, 603, 610–614, 616–621, 623–627, 660, 662, 669–673, 675–680, 682, 684–685, 687–690, 692–693, 748, 784–787, 790, 792, 795, 797, 799, 825, 888, 933–934, 937, 939, 949–954, 957, 965, 965–971, 973, 975, 996–997
   CanvasOptions.ts100%100%100%100%
   SelectableCanvas.ts85.43%53.94%100%94.39%1006, 1008–1009, 1026, 1035, 1103–1107, 1153–1154, 1156–1157, 1159, 1186, 1188–1189, 1189, 1191, 1233, 1235, 1237, 1253, 1255, 1283, 1286, 1329–1336, 1339, 1342, 1351–1352, 1356–1365, 1369, 1371–1372, 1378–1383, 1387, 340–342, 346, 376, 398, 476, 527, 529, 605, 610, 687, 715
   StaticCanvas.ts75.81%69.50%98.91%75.38%1000, 1006, 1009, 1011, 1013, 1021, 1023–1029, 1039, 1042, 1045–1051, 1053–1054, 1056–1077, 1084–1086, 1088, 1096, 1102, 1104, 1104–1105, 1105–1106, 1108, 1108–1113, 1126, 1131–1133, 1137, 1141, 1143, 1145, 1150–1154, 1156, 1158–1161, 1164, 1166, 1175, 1177–1178, 1185–1188, 1190, 1196–1199, 1203–1204, 1214, 1220–1222, 1224–1229, 1229, 1229–1233, 1233, 1233–1238, 1240–1247, 1276–1277, 1279–1284, 1286–1292, 1296, 1298–1311, 1319–1320, 1330, 1341, 1382–1386, 1388, 1390, 1392–1396, 1415, 1431, 1448, 1468, 1501, 1505, 1516–1518, 425, 436,

@asturur asturur merged commit f8fdc26 into master Aug 15, 2024
20 checks passed
@asturur asturur deleted the fromObject-clone-cleanup branch August 15, 2024 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants