Skip to content

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Jan 19, 2026

Summary

  • Remove unnecessary ancestors.to_vec() allocation at the start of recursion
  • Replace ancestors.clone().into_iter() with ancestors.iter().cloned() to avoid intermediate Vec allocation

Before

Each recursion level:

  1. ancestors.to_vec() - O(n) allocation to convert slice to Vec
  2. For each subcommand: ancestors.clone().into_iter() - O(n) allocation to clone the Vec

After

Each recursion level:

  1. No upfront allocation
  2. For each subcommand: ancestors.iter().cloned() - lazy iteration, cloning elements only as needed

This eliminates two Vec allocations per recursion level, which adds up for deeply nested subcommand structures.

🤖 Generated with Claude Code


Note

Optimizes recursive construction of full_cmd for subcommands to reduce allocations.

  • Replace ancestors.clone().into_iter() with ancestors.iter().cloned() when building full_cmd
  • Remove upfront ancestors.to_vec() allocation
  • Pass child_ancestors (a local clone of full_cmd) into recursive calls instead of cloning inline

Written by Cursor Bugbot for commit e3a4c9d. This will update automatically on new commits. Configure here.

Replace `ancestors.to_vec()` followed by `ancestors.clone().into_iter()`
with direct `ancestors.iter().cloned()`. This eliminates two Vec allocations
per recursion level (one for the to_vec() and one for each subcommand's clone()).

The improvement:
- Before: O(n) Vec allocation for to_vec() + O(n) Vec allocation per subcommand
- After: O(n) lazy iteration with element-by-element cloning (no intermediate Vec)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 19, 2026 19:09
Copy link
Contributor

Copilot AI left a comment

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 set_subcommand_ancestors function by eliminating unnecessary allocations during recursion. The changes remove redundant vector cloning operations that were creating O(n) allocations at each recursion level.

Changes:

  • Removed upfront ancestors.to_vec() allocation at the start of the function
  • Replaced ancestors.clone().into_iter() with ancestors.iter().cloned() for lazy iteration
  • Introduced temporary variable to avoid cloning during recursive call

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.36%. Comparing base (9df7c86) to head (e3a4c9d).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
lib/src/spec/mod.rs 0.00% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #448   +/-   ##
=======================================
  Coverage   47.36%   47.36%           
=======================================
  Files          47       47           
  Lines        6653     6653           
  Branches     6653     6653           
=======================================
  Hits         3151     3151           
  Misses       1739     1739           
  Partials     1763     1763           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jdx jdx merged commit 875eff3 into main Jan 19, 2026
10 of 11 checks passed
@jdx jdx deleted the feat/fix-unnecessary-clone branch January 19, 2026 19:45
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