Skip to content

⚡ Optimize submodule lookup by avoiding redundant string clones#57

Open
bashandbone wants to merge 1 commit intomainfrom
perf-optimize-submodule-lookup-8596418518332672665
Open

⚡ Optimize submodule lookup by avoiding redundant string clones#57
bashandbone wants to merge 1 commit intomainfrom
perf-optimize-submodule-lookup-8596418518332672665

Conversation

@bashandbone
Copy link
Copy Markdown
Owner

💡 What: The optimization replaces entry.path.as_ref().map(|p| p.to_string()).unwrap_or(name.clone()) with entry.path.as_deref().unwrap_or(name) in src/git_ops/git2_ops.rs.

🎯 Why: The previous implementation forced heap allocations in two ways:

  1. map(|p| p.to_string()) allocated a new string for path even though find_submodule only needs a &str.
  2. unwrap_or(name.clone()) eagerly cloned the name string on every iteration, even when path was Some.

📊 Measured Improvement: I was unable to show a meaningful performance improvement using the provided cargo bench or cargo test because the environment lacked necessary dependencies (like bitflags) and had no network access to fetch them. However, the theoretical benefit is clear: it avoids at least one String allocation per submodule during the .gitmodules write operation, which is a significant reduction in overhead for repositories with many submodules. I verified the logical equivalence of the change using a standalone rustc script.


PR created automatically by Jules for task 8596418518332672665 started by @bashandbone

Replaced inefficient string allocations with `as_deref()` and direct reference lookup.
- Avoids `String` allocation when `path` is `Some`.
- Avoids eager `clone()` of `name` when `path` is `Some`.
- Resulting code is more idiomatic and memory-efficient.

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings April 20, 2026 00:14
Copy link
Copy Markdown
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

Optimizes submodule lookup during .gitmodules writing by avoiding unnecessary String allocations/clones when calling git2::Repository::find_submodule.

Changes:

  • Replace to_string()/clone()-based temporary String construction with Option::as_deref() and unwrap_or on &str.
  • Reduce per-submodule heap allocation overhead in write_gitmodules.

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

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