Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

[Perf] Fix low efficient loops for large batchs - #91

Merged
0oshowero0 merged 4 commits into
TransferQueue:devfrom
baymax591:dev
Oct 28, 2025
Merged

0oshowero0 merged 4 commits into
TransferQueue:devfrom
baymax591:dev

Conversation

@baymax591

@baymax591 baymax591 commented Oct 27, 2025 •

Copy link
Copy Markdown
Contributor

as titile

Summary by CodeRabbit

  • Refactor
    • Optimized internal data processing logic for improved efficiency. No changes to user-facing functionality.

@coderabbitai

coderabbitai Bot commented Oct 27, 2025 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

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

Walkthrough

The _add_field_data function in transfer_queue/storage.py was refactored to replace iterative per-sample data appends with a batched index-based approach using itemgetter, handling single and multiple indexes distinctly while maintaining identical external behavior.

Changes

Cohort / File(s) Summary
Storage optimization
transfer_queue/storage.py
Refactored _add_field_data to compute batch indexes from storage metadata and use itemgetter for batched data extraction/reordering instead of per-sample append loops; added local itemgetter import within the function.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify the index extraction logic from sample_metas correctly handles both single and multiple index cases
  • Confirm the itemgetter reordering produces identical data ordering as the previous loop-based approach
  • Check that the local itemgetter import doesn't conflict with module-level imports

Poem

🐰 Hopping through the indexes bright,
Batch by batch, reorder with might,
No more loops that slowly creep,
ItemGetter makes data leap! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title Check ✅ Passed The pull request title "[Perf] Fix low efficient loops for large batchs" is directly related to the main change in the changeset. The PR modifies the _add_field_data function to replace per-sample append loops with a more efficient batched/index-based approach using itemgetter for data extraction and reordering. The title accurately reflects this performance optimization objective, using the [Perf] prefix to indicate it's a performance improvement and mentioning "loops" and "large batchs" which correspond to the actual code changes. While the title has minor grammatical imperfections (typo: "batchs" should be "batches"), it successfully communicates the primary intent of the changeset.

Comment @coderabbitai help to get the list of available commands and usage tips.

@baymax591 baymax591 reopened this Oct 27, 2025
@0oshowero0
0oshowero0 requested a review from Copilot October 28, 2025 02:27
@0oshowero0

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 28, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 itemgetter for 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.

Comment thread transfer_queue/storage.py Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
transfer_queue/storage.py (1)

776-776: Remove redundant local import.

The itemgetter import 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9ff2fa5 and da4a7ba.

📒 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 index list derived from sample_metas will always be non-empty, and itemgetter(*index) will never fail.

Likely an incorrect or invalid review comment.

Comment thread transfer_queue/storage.py Outdated
>>> result = _add_field_data(transfer_dict, meta_group, data)
>>> result["field_data"]["images"] # [img2, img0, img3] - extracted by batch_index
"""
from operator import itemgetter

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe put this at the beginning of the file?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it's just repeated

@0oshowero0 0oshowero0 changed the title accelerate add_fiele_data [Perf] Fix low efficient loops for Oct 28, 2025
@0oshowero0 0oshowero0 changed the title [Perf] Fix low efficient loops for [Perf] Fix low efficient loops for large batchs Oct 28, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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()}

Copilot uses AI. Check for mistakes.
Comment thread transfer_queue/storage.py
if len(fields) == 1:
extracted_data = {fields[0]: field_values}
else:
extracted_data = dict(zip(fields, field_values, strict=False))

Copilot AI Oct 28, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Suggested change
extracted_data = dict(zip(fields, field_values, strict=False))
extracted_data = dict(zip(fields, field_values, strict=True))

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <[email protected]>
@0oshowero0
0oshowero0 merged commit c889427 into TransferQueue:dev Oct 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants