Skip to content

fix(amazonq): limit diff and similarity work for large edit suggestions - #2934

Merged
hezelin-work merged 1 commit into
feature/OHIfrom
fix/inline-completion-diff-limits
Oct 14, 2026
Merged

hezelin-work merged 1 commit into
feature/OHIfrom
fix/inline-completion-diff-limits

Conversation

@hezelin-work

@hezelin-work hezelin-work commented Oct 14, 2026 •

Copy link
Copy Markdown

Problem

Diff calculation for large edit suggestions was slow.

Solution

Limit the diff work for large edit suggestions.

Testing: added unit tests.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

- Compute the accepted-edit character diff with two rows instead of a
  full table, skip the common prefix and suffix, and approximate it
  when the table would exceed 1,000,000 cells.
- Compare rejected edits by edit distance only up to 2,000 characters.
  Longer edits match only an identical rejection, which is unchanged
  for the default threshold of 1.0.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@hezelin-work
hezelin-work marked this pull request as ready for review October 14, 2026 15:39
@hezelin-work
hezelin-work requested a review from a team as a code owner October 14, 2026 15:39

@ashishrp-aws ashishrp-aws left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI-assisted review at c333953.

Approving.

  • Prefix/suffix trimming is exact. A common prefix and suffix are always part of some LCS, and the suffix bound shorterLength - prefixLength prevents overlap.
  • The two-row Uint32Array LCS is correct. current[0] stays 0 across swaps, and every j is rewritten on each row.
  • The cap degrades only telemetry. Inputs over the cap report the middle as fully replaced, and getCharacterDifferences is only used for the accept-telemetry character counts (sessionResultsHandler.ts:103).
  • RejectedEditTracker filtering is unchanged at the default threshold. calculateSimilarity short-circuits str1 === str2 before the length cap, and the default threshold is 1.0. Hoisting normalizeEditContent(content) out of the loop is a nice win.

Non-blocking:

  • The similarityThreshold JSDoc/config should say that edits over MAX_SIMILARITY_INPUT_LENGTH only ever match identically. Anyone lowering the threshold below 1.0 will otherwise be surprised.
  • Optional: normalize each rejection once when it's recorded instead of on every comparison. It's a small cost now, but it's per suggestion × 50 entries.

@hezelin-work
hezelin-work merged commit a7e7fee into feature/OHI Oct 14, 2026
5 checks passed
@hezelin-work
hezelin-work deleted the fix/inline-completion-diff-limits branch October 14, 2026 23:31
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.

4 participants