Copilot commented on code in PR #3667:
URL: https://github.com/apache/texera/pull/3667#discussion_r2281046535


##########
core/gui/src/app/common/util/workflow-compilation-utils.ts:
##########
@@ -30,7 +30,12 @@ export function areAllPortSchemasEqual(schemas: (PortSchema 
| undefined)[]): boo
   if (schemas.length <= 1) {
     return true;
   }
-  return schemas.every(schema => schema === schemas[0]);
+  if (schemas[0] === undefined) {
+    return schemas.every(schema => schema === undefined);
+  } else {
+    const firstSchemaString = JSON.stringify(schemas[0]);

Review Comment:
   Using JSON.stringify for equality comparison can be inefficient and 
unreliable. JSON.stringify doesn't guarantee consistent property ordering, 
which could cause structurally identical objects to be considered different. 
Consider using a dedicated deep equality function like lodash's isEqual or 
implementing a proper equality method for PortSchema objects.



##########
core/gui/src/app/common/util/workflow-compilation-utils.ts:
##########
@@ -30,7 +30,12 @@ export function areAllPortSchemasEqual(schemas: (PortSchema 
| undefined)[]): boo
   if (schemas.length <= 1) {
     return true;
   }
-  return schemas.every(schema => schema === schemas[0]);
+  if (schemas[0] === undefined) {
+    return schemas.every(schema => schema === undefined);
+  } else {
+    const firstSchemaString = JSON.stringify(schemas[0]);
+    return schemas.every(schema => schema !== undefined && 
JSON.stringify(schema) === firstSchemaString);

Review Comment:
   JSON.stringify is called for every schema in the array, which is inefficient 
for large arrays. The stringification of the first schema should be done once 
(which is correct), but calling JSON.stringify in the loop for each comparison 
is wasteful. Consider caching the stringified versions or using a more 
efficient comparison method.
   ```suggestion
       const schemaStrings = schemas.map(schema => schema === undefined ? 
undefined : JSON.stringify(schema));
       return schemaStrings.every(str => str === firstSchemaString);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to