Skip to content

Share repeated itertools.product pools - #9323

Merged
youknowone merged 1 commit into
RustPython:mainfrom
1ndahous3:product_shared_pools
Oct 23, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
1ndahous3:product_shared_pools

Conversation

@1ndahous3

@1ndahous3 1ndahous3 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Share immutable input pools across repeated dimensions and reuse exact tuple inputs instead of copying their element references.
  • Leave input iterators untouched when repeat=0.
  • Advance indices iteratively and serialize the exhaustion check with index updates.

Performance

Windows 11 x64

Operation Main Patch Speedup
Construct from a 100-item tuple, repeat=4 1.66 µs 0.88 µs 1.9×
Construct from a 10,000-item list, repeat=8 683.18 µs 115.31 µs 5.9×

Debian 13 amd64

Operation Main Patch Speedup
Construct from a 100-item tuple, repeat=4 1.42 µs 0.80 µs 1.8×
Construct from a 10,000-item list, repeat=8 659.49 µs 113.18 µs 5.8×

For the list workload, repeated pools retain 10,000 element references instead of 80,000.

AI assistance

Written with Codex (GPT-6), reviewed by a human before submission.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed itertools.product behavior when repeat=0. It now yields the expected single empty tuple without consuming the input iterator, leaving its items available for subsequent iteration.

Assisted-by: Codex:GPT-6
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T06:39:52.091258Z d72f06d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between e5554e2 and d72f06d.

📒 Files selected for processing: 2
  • crates/vm/src/stdlib/itertools.rs
  • extra_tests/snippets/stdlib_itertools.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Walkthrough

itertools.product now stores pools as tuple references and uses iterative index advancement. When repeat is zero, construction skips input conversion. A test checks that the result is one empty tuple and that the input iterator remains unconsumed.

Changes: Product iterator

Layer / File(s) Summary
Pool construction and iteration
crates/vm/src/stdlib/itertools.rs, extra_tests/snippets/stdlib_itertools.py
The iterator stores pool tuples and uses reverse iterative carry to advance indices. With repeat=0, it skips input conversion. The added test checks for one empty tuple and an unconsumed input iterator.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Refactor

Possibly related issues

  • RustPython/RustPython#6839 — This change updates itertools.product behavior and adds a standard-library test, which may relate to the issue’s goal of matching newer CPython behavior.

Suggested reviewers: youknowone

Merge Risk: ⚪ Minimal · up to d72f0

The product iterator change has no identified merge-blocking issue.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies the main change: sharing repeated input pools in itertools.product.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d72f06dacf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/vm/src/stdlib/itertools.rs Resolved
@codspeed

codspeed Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing 1ndahous3:product_shared_pools (d72f06d) with main (e5554e2)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@youknowone
youknowone merged commit bbbde24 into RustPython:main Oct 23, 2026
22 checks passed
@1ndahous3
1ndahous3 deleted the product_shared_pools branch October 25, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants