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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Improve performance of record message serialization #1196

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions singer_sdk/_singerlib/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ class RecordMessage(Message):
time_extracted: datetime | None = None
"""The time the record was extracted."""

def to_dict(self) -> dict[str, t.Any]:
"""Return a dictionary representation of the message.

This overrides the default conversion logic, since it uses unnecessary
deep copying and is very slow.

Returns:
A dictionary with the defined message fields.
"""
result: dict[str, t.Any] = {
"type": "RECORD",
"stream": self.stream,
"record": self.record,
}
if self.version is not None:
result["version"] = self.version
if self.time_extracted is not None:
result["time_extracted"] = self.time_extracted
return result

def __post_init__(self) -> None:
"""Post-init processing.

Expand Down