Repository navigation
Conversation
Replace per-field filter callbacks with direct loops in DataContainer.__repr__. Reuse getattr within each call and keep version checks, field order, defaults, and output formatting. Offset-commit DEBUG batches measured 211.54 ms before and 202.49 ms after, using median batch times across three runs. Validation: consumer coordinator/fetcher, producer sender/transaction manager, and protocol tests: 1473 passed, 1 skipped. Changed-file pylint errors-only and git diff --check pass. Co-Authored-By: Aiden <aiden@weco.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
DataContainer.__repr__during offset-commit DEBUG logging.getattrwithin each call.pytestconsumer coordinator/fetcher, producer sender/transaction manager, and protocol suites; 1,473 passed, one skipped.What & Why
Before,
__repr__called a filter callback for every field, even when the object had no version.Use separate loops for versioned and unversioned objects, and reuse
getattrwithin each call.The loops keep the same version checks, field order, value conversion, and output format.
The measured benefit applies to protocol DEBUG logging during offset commits.
The change removes callback work each time a request or response is formatted for a log message.
Validation
Measured with CPython 3.12.13 on Linux x86_64.
The DEBUG row reports median batch times across three runs.
Each batch repeats 56 exchanges and representation edge cases 64 times.
The exchange mix covers versions 0, 1, 2, 3, 4, 6, and 8.
It includes encoding, decoding, and in-memory DEBUG formatting; socket IO and fixture setup are excluded.
The encode/decode rows are pyperf means from the repository's protocol benchmark.
These paths do not call
repr; both shown decode cases have no significant change.ApiVersions encoding measured 1.7% more time, so no improvement is claimed for that case.
Reproduce the repository protocol benchmarks before and after applying the patch:
The DEBUG workload follows the offset-commit exchanges exercised by
test_send_offset_commit_request_versions.The native validation command passed with 1,473 passed, one skipped:
pylint --errors-only kafka/protocol/data_container.pyandgit diff --checkalso pass.Why this is safe and easy to maintain
The change is small and uses two simple loops.
It keeps field order, version checks, defaults, exception behavior, and the exact output.
The native consumer, producer, and protocol tests pass.
Exact-output checks also cover nested values, missing fields, Unicode, and exceptions.
AI assistance
Codex gpt-6.1-sol generated the candidate changes, tracked with Weco Observe.
Automated evaluation and local tests checked the selected change.
Weco share link: https://dashboard.weco.ai/share/OVatIaYwk1yutr81Fe4LWzSbAO5u4-Xe