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


##########
amber/src/main/python/pytexera/workflow/codec.py:
##########
@@ -0,0 +1,157 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Cloudpickle transport for explicit workflow boundary payloads."""
+
+from __future__ import annotations
+
+import pickle
+from dataclasses import dataclass
+
+import cloudpickle
+
+
+@dataclass(frozen=True)
+class BoundaryPayload:
+    """One boundary contract, its path-present fields, and encoded values."""
+
+    boundary_id: str
+    fields: tuple[str, ...]
+    present: tuple[str, ...]
+    payload: bytes
+
+    def __post_init__(self) -> None:
+        if not isinstance(self.boundary_id, str):
+            raise TypeError("boundary ID must be a string")
+        if not self.boundary_id:
+            raise ValueError("boundary ID must be nonempty")
+        if not isinstance(self.fields, tuple) or any(
+            not isinstance(field, str) for field in self.fields
+        ):
+            raise TypeError("boundary fields must be a tuple of strings")
+        if self.fields != tuple(sorted(set(self.fields))) or any(
+            not field.isidentifier() for field in self.fields
+        ):
+            raise ValueError("boundary fields must be canonical Python names")
+        if not isinstance(self.present, tuple) or any(
+            not isinstance(field, str) for field in self.present
+        ):
+            raise TypeError("present fields must be a tuple of strings")
+        if self.present != tuple(
+            field for field in self.fields if field in frozenset(self.present)
+        ):

Review Comment:
   The generator rebuilds `frozenset(self.present)` for every contract field, 
so validating an all-present boundary with n fields performs O(n²) work and 
allocates n sets. This cost repeats during boundary and envelope 
encoding/decoding. Compute the present-field set once before the comprehension 
so subset validation is linear.



-- 
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