Repository navigation
[Perf] Fix low efficient loops for large batchs - #91
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the _add_field_data function by replacing a loop-based approach with Python's built-in itemgetter for extracting field data by batch indices.
Key changes:
- Replaced loop iteration with
itemgetterfor batch indexing - Pre-computed batch indices in a list comprehension
- Added special handling for single-index case
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
transfer_queue/storage.py (1)
776-776: Remove redundant local import.The
itemgetterimport on Line 776 is redundant since it's already imported at module scope on Line 23.Apply this diff to remove the redundant import:
- from operator import itemgetter - field_names = transfer_dict["fields"]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
transfer_queue/storage.py(1 hunks)
🔇 Additional comments (1)
transfer_queue/storage.py (1)
776-786: The review comment's concern about empty sample_metas is incorrect.The code is safe as-is. StorageMetaGroups are created only when a sample is encountered, and add_sample_meta() is called immediately after creation. Groups are only stored in the storage_meta_groups dict when they have samples. Since add_sample_meta() unconditionally appends samples and local_indexes without filtering, and samples are never removed, the sample_metas list will never be empty when _add_field_data() is called. Therefore, the
indexlist derived from sample_metas will always be non-empty, anditemgetter(*index)will never fail.Likely an incorrect or invalid review comment.
| >>> result = _add_field_data(transfer_dict, meta_group, data) | ||
| >>> result["field_data"]["images"] # [img2, img0, img3] - extracted by batch_index | ||
| """ | ||
| from operator import itemgetter |
There was a problem hiding this comment.
maybe put this at the beginning of the file?
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| merged_extra_info = {} | ||
| for chunk in data: | ||
| merged_extra_info.update(chunk.extra_info) | ||
| merged_extra_info = dict(ChainMap(*(chunk.extra_info for chunk in data))) |
There was a problem hiding this comment.
ChainMap merges dictionaries in reverse priority order (first in chain has highest priority), but the original code uses update() which gives later chunks higher priority. This changes the behavior when duplicate keys exist across chunks. Use {k: v for chunk in reversed(data) for k, v in chunk.extra_info.items()} or iterate forward with update to maintain original semantics.
| merged_extra_info = dict(ChainMap(*(chunk.extra_info for chunk in data))) | |
| merged_extra_info = {k: v for chunk in data for k, v in chunk.extra_info.items()} |
| if len(fields) == 1: | ||
| extracted_data = {fields[0]: field_values} | ||
| else: | ||
| extracted_data = dict(zip(fields, field_values, strict=False)) |
There was a problem hiding this comment.
[nitpick] The strict=False parameter is unnecessary here since fields and field_values (from itemgetter) are guaranteed to have the same length. Consider removing it or using strict=True for additional safety.
| extracted_data = dict(zip(fields, field_values, strict=False)) | |
| extracted_data = dict(zip(fields, field_values, strict=True)) |
Co-authored-by: Copilot <[email protected]>
as titile
Summary by CodeRabbit