Skip to content

Conversation

Copy link

Copilot AI commented Dec 31, 2025

Identified and fixed inefficient string handling patterns that cause unnecessary heap allocations in hot paths (progress rendering, benchmarking, LSP operations).

Changes

  • Replace push_str(&format!(...)) with write! macro - Eliminates intermediate String allocation per call

    // Before: allocates temporary String
    text.push_str(&format!("{}", value));
    
    // After: writes directly
    let _ = write!(text, "{}", value);
  • Remove redundant .to_string() after .join() - .join() already returns String

  • Use into_iter() instead of .iter().map(|s| s.to_string()) - Moves owned strings rather than cloning

  • Optimize hex fingerprint formatting - Replaced N allocations with single pre-sized buffer using write! in loop

  • Eliminate intermediate Vec in string building - Changed .collect::<Vec<_>>().join("\n") to direct string building with conditional newlines

Impact

Most significant in:

  • cli/lsp/language_server.rs - Status page generation (68 net line change)
  • cli/tools/bench/mitata.rs - Benchmark output formatting
  • ext/node/ops/crypto/x509.rs - Certificate fingerprint computation

10 files modified. All changes maintain existing APIs and behavior.

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.

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

Copilot AI and others added 3 commits December 31, 2025 14:01
- Replace push_str(&format!(...)) with write! macro to avoid temporary allocations
- Remove redundant .to_string() after .join() which already returns String
- Simplify format!(...).as_str().as_bytes() to format!(...).as_bytes()
- Remove unnecessary .to_string() when converting owned strings in collections
- Optimize hex formatting in x509.rs to avoid repeated allocations
- Optimize string building in language_server.rs to avoid Vec intermediates

Co-authored-by: bartlomieju <[email protected]>
- Move std::fmt::Write import to top-level imports in x509.rs
- Optimize percentiles formatting in mitata.rs to avoid nested format! calls

Co-authored-by: bartlomieju <[email protected]>
Use .to_owned() instead of .to_string() on &str as it more clearly
expresses the intent to take ownership of borrowed data.

Co-authored-by: bartlomieju <[email protected]>
Copilot AI changed the title [WIP] Identify and suggest improvements to slow code Optimize string formatting to reduce allocations Dec 31, 2025
Copilot AI requested a review from bartlomieju December 31, 2025 14:10
@bartlomieju bartlomieju closed this Jan 7, 2026
@bartlomieju bartlomieju deleted the copilot/identify-code-improvements branch January 7, 2026 15:09
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