Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 1, 2025

Identified and fixed inefficient string concatenation patterns causing unnecessary allocations in frequently-executed code paths.

Changes

  • compile_boolean_matcher.rs: Pre-allocate string capacity and use push_str() instead of += operator when building single-character regex patterns
  • dependencies_block.rs: Replace fold with += with idiomatic map().collect::<String>() pattern for dependency ID generation
  • eval/mod.rs: Replace manual loop with iterator-based collection for template string evaluation

Example

Before:

let mut single_char_items: String = String::new();
for item in items {
  if item.chars().count() == 1 {
    single_char_items += &item;  // Repeated allocations
  }
}

After:

let mut single_char_items = String::with_capacity(count_of_single_char_items);
for item in items {
  if item.chars().count() == 1 {
    single_char_items.push_str(&item);  // No reallocation
  }
}

Additional Observations

Minor optimization opportunities remain but are out of scope for this focused change:

  • .chars().count() == 1 could use early termination
  • Some HashMap/HashSet instances lack capacity hints
Original prompt

Identify and suggest improvements to slow or inefficient code


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@netlify
Copy link

netlify bot commented Nov 1, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit be810f7
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6905e143e1046600089f403c

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Co-authored-by: hardfist <8898718+hardfist@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and suggest improvements for slow code Optimize string concatenation in hot paths Nov 1, 2025
Copilot finished work on behalf of hardfist November 1, 2025 10:39
Copilot AI requested a review from hardfist November 1, 2025 10:39
@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2025

📦 Binary Size-limit

Comparing be810f7 to chore(deps): update dependency @biomejs/biome to ^2.3.2 (#12055) by renovate[bot]

🙈 Size remains the same at 47.85MB

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 3, 2025

CodSpeed Performance Report

Merging #12058 will not alter performance

Comparing copilot/identify-inefficient-code (be810f7) with main (d808219)

Summary

✅ 17 untouched

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.

3 participants