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

⚡️ Speed up method ResultData.serialize_results by 22% in PR #6028 (PlaygroundPage) #6205

Open
wants to merge 1 commit into
base: PlaygroundPage
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/backend/base/langflow/serialization/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,38 +239,36 @@
"""
if obj is None:
return None

if isinstance(obj, (str, int, float, bool, type(None))):

Check failure on line 243 in src/backend/base/langflow/serialization/serialization.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (UP038)

src/backend/base/langflow/serialization/serialization.py:243:8: UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)`
return obj # Directly return primitive types

try:
# First try type-specific serialization
result = _serialize_dispatcher(obj, max_length, max_items)
if result is not UNSERIALIZABLE_SENTINEL: # Special check for None since it's a valid result
if result is not UNSERIALIZABLE_SENTINEL:
return result

# Handle class-based Pydantic types and other types
if isinstance(obj, type):
if issubclass(obj, BaseModel | BaseModelV1):
if issubclass(obj, (BaseModel, BaseModelV1)):

Check failure on line 252 in src/backend/base/langflow/serialization/serialization.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (UP038)

src/backend/base/langflow/serialization/serialization.py:252:16: UP038 Use `X | Y` in `issubclass` call instead of `(X, Y)`
return repr(obj)
return str(obj) # Handle other class types
return str(obj)

# Handle type aliases and generic types
if hasattr(obj, "__origin__") or hasattr(obj, "__parameters__"): # Type alias or generic type check
try:
return repr(obj)
except Exception as e: # noqa: BLE001
logger.debug(f"Cannot serialize object {obj}: {e!s}")
if hasattr(obj, "__origin__") or hasattr(obj, "__parameters__"):
return repr(obj)

# Fallback to common serialization patterns
if hasattr(obj, "model_dump"):
return serialize(obj.model_dump(), max_length, max_items)

if hasattr(obj, "dict") and not isinstance(obj, type):
return serialize(obj.dict(), max_length, max_items)

# Final fallback to string conversion only if explicitly requested
if to_str:
return str(obj)

except Exception as e: # noqa: BLE001
except Exception as e:

Check failure on line 268 in src/backend/base/langflow/serialization/serialization.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (BLE001)

src/backend/base/langflow/serialization/serialization.py:268:12: BLE001 Do not catch blind exception: `Exception`
logger.debug(f"Cannot serialize object {obj}: {e!s}")
return "[Unserializable Object]"

return obj


Expand Down
Loading