Skip to content

Conversation

@Hweinstock
Copy link
Contributor

@Hweinstock Hweinstock commented May 12, 2025

Problem

When typing a decent amount of text in quick succession, the language server will get throttled in its requests to the backend. This is because we send a request for recommendations on every key stroke, causing the language server to make a request on each key stroke. This is rightfully getting throttled by the backend.

Solution

  • The ideal behavior is that we only make a request to the language server, and thus to the backend, when typing stops. Therefore, this is an ideal use case for debounce. However, we need to extend debounce slightly outlined below.
  • Apply debounce to the recommendations such that we wait 20 ms after typing stops before fetching the results.
  • By applying this at the recommendation level, none of the inline latency metrics are affected.

Debounce Changes

-Let f be some debounced function that takes a string argument, our current debounce does the following:

f('a') f('ab') f('abc') (pause for debounce delay) -> f would be called with 'a'

The issue is is that for suggestions, this means the language server request will be made with stale context (i.e. not including our most recent content). What we want instead is for the case above to call f with 'abc' and not with 'a' or 'ab'.

We can accomplish this by adding a flag to debounce allowing us to choose whether we call it with the first args of the debounce interval (default, and 'a' in the example above), or the most recent args ('abc' in the example above).

Verification

  • I did not notice the added latency when testing inline. However it does seem slower than prod, with and without this change.
  • I was not able to get a throttling exception.

  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions

This comment was marked as off-topic.

@Hweinstock Hweinstock changed the title fix(amazonq): debounce inline suggestion requests. fix(amazonq): debounce inline suggestion requests. (WIP) May 12, 2025
@Hweinstock Hweinstock changed the title fix(amazonq): debounce inline suggestion requests. (WIP) fix(amazonq): debounce inline suggestion requests. May 12, 2025
* the interval of the background thread invocation, which is triggered by the timer
* Delay for making requests once the user stops typing. Without a delay, inline suggestions request is triggered every keystroke.
*/
export const defaultCheckPeriodMillis = 1000 * 60 * 5
Copy link
Contributor Author

Choose a reason for hiding this comment

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

didn't see these used anymore, so I deleted for clarity.

Copy link
Contributor

Choose a reason for hiding this comment

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

these were probably missed when I was deleting code. One of the problems with exporting in typescript is that it makes it very hard to detect which exports are actually used

@Hweinstock Hweinstock marked this pull request as ready for review May 12, 2025 19:17
@Hweinstock Hweinstock requested review from a team as code owners May 12, 2025 19:17
* the interval of the background thread invocation, which is triggered by the timer
* Delay for making requests once the user stops typing. Without a delay, inline suggestions request is triggered every keystroke.
*/
export const defaultCheckPeriodMillis = 1000 * 60 * 5
Copy link
Contributor

Choose a reason for hiding this comment

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

these were probably missed when I was deleting code. One of the problems with exporting in typescript is that it makes it very hard to detect which exports are actually used

@Hweinstock
Copy link
Contributor Author

Could we use something like https://www.npmjs.com/package/ts-unused-exports? I just ran it and got 951 results, so this might be noisy. Perhaps something to investigate in the future if more bandwidth is available.

@Hweinstock Hweinstock merged commit 0429352 into aws:feature/flare-inline May 12, 2025
32 of 37 checks passed
@Hweinstock Hweinstock deleted the fix/throttle branch May 12, 2025 20:11
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