Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 5, 2025

Closes: N/A (performance improvement)

Description

Identified and eliminated allocation hotspots in code formatting, completion, and diagnostic passes. Changes target repeated string allocations in nested formatting loops, unnecessary clones in completion item construction, and inefficient case-insensitive comparisons.

Changes

Formatting (format.rs)

  • Cache indentation strings for nesting levels 0-10, eliminating repeat() calls in hot paths
  • Replace chars.collect::<String>() with direct buffer extension
  • Use any() instead of contains() for character searches

Completion (completion.rs)

  • Remove 4 unnecessary string clones when constructing CompletionItems
  • Move values instead of cloning where ownership permits
  • Eliminate no-op map transformation

String utilities (utils.rs)

  • Rewrite starts_with_lowercase() to avoid allocating two lowercased strings
  • Add ASCII fast path using eq_ignore_ascii_case()
  • Fall back to Unicode comparison only when needed

Diagnostics (unused.rs)

  • Create new cursor for parameter iteration instead of cloning

Impact

4 files changed: +67/-24 lines. All tests pass, no functionality changes.

Tradeoffs

  • IndentCache adds ~10 pre-allocated strings per format operation, negligible memory overhead for significant allocation reduction
  • ASCII fast path in starts_with_lowercase() adds slight complexity but maintains full Unicode support
Original prompt

Identify and suggest improvements to slow or inefficient code


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Identify and suggest improvements for slow code Optimize hot paths: reduce allocations in formatting, completion, and diagnostics Nov 5, 2025
Copilot AI requested a review from felix-andreas November 5, 2025 21:59
Copilot finished work on behalf of felix-andreas November 5, 2025 21:59
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