Skip to content

Commit 7f36a2d

Browse files
authored
config(amazonq): disable inline tutorial since it's taking ~250ms for all users no matter it's shown or not (#7722)
… ## Problem by design, the code path should only be applied to "new" users, however currently it's taking 250ms for all users no matter the UI is displayed or not. <img width="843" height="264" alt="image" src="https://github.com/user-attachments/assets/1d70bb30-a7c6-4f71-b65b-e1d171c85b9d" /> ## Solution --- - 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](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 6c79154 commit 7f36a2d

File tree

3 files changed

+40
-46
lines changed

3 files changed

+40
-46
lines changed

packages/amazonq/src/app/inline/completion.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class InlineCompletionManager implements Disposable {
198198
}
199199

200200
export class AmazonQInlineCompletionItemProvider implements InlineCompletionItemProvider {
201-
private logger = getLogger('nextEditPrediction')
201+
private logger = getLogger()
202202
constructor(
203203
private readonly languageClient: LanguageClient,
204204
private readonly recommendationService: RecommendationService,
@@ -299,7 +299,8 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
299299
}
300300
// re-use previous suggestions as long as new typed prefix matches
301301
if (prevItemMatchingPrefix.length > 0) {
302-
getLogger().debug(`Re-using suggestions that match user typed characters`)
302+
logstr += `- not call LSP and reuse previous suggestions that match user typed characters
303+
- duration between trigger to completion suggestion is displayed ${performance.now() - t0}`
303304
return prevItemMatchingPrefix
304305
}
305306
getLogger().debug(`Auto rejecting suggestions from previous session`)
@@ -318,7 +319,6 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
318319
this.sessionManager.clear()
319320
}
320321

321-
// TODO: this line will take ~200ms each trigger, need to root cause and maybe better to disable it for now
322322
// tell the tutorial that completions has been triggered
323323
await this.inlineTutorialAnnotation.triggered(context.triggerKind)
324324

@@ -346,12 +346,13 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
346346

347347
const t2 = performance.now()
348348

349-
logstr = logstr += `- number of suggestions: ${items.length}
349+
logstr += `- number of suggestions: ${items.length}
350350
- sessionId: ${this.sessionManager.getActiveSession()?.sessionId}
351351
- first suggestion content (next line):
352352
${itemLog}
353-
- duration since trigger to before sending Flare call: ${t1 - t0}ms
354-
- duration since trigger to receiving responses from Flare: ${t2 - t0}ms
353+
- duration between trigger to before sending LSP call: ${t1 - t0}ms
354+
- duration between trigger to after receiving LSP response: ${t2 - t0}ms
355+
- duration between before sending LSP call to after receving LSP response: ${t2 - t1}ms
355356
`
356357
const session = this.sessionManager.getActiveSession()
357358

@@ -361,16 +362,13 @@ ${itemLog}
361362
}
362363

363364
if (!session || !items.length || !editor) {
364-
getLogger().debug(
365-
`Failed to produce inline suggestion results. Received ${items.length} items from service`
366-
)
365+
logstr += `Failed to produce inline suggestion results. Received ${items.length} items from service`
367366
return []
368367
}
369368

370369
const cursorPosition = document.validatePosition(position)
371370

372371
if (position.isAfter(editor.selection.active)) {
373-
getLogger().debug(`Cursor moved behind trigger position. Discarding suggestion...`)
374372
const params: LogInlineCompletionSessionResultsParams = {
375373
sessionId: session.sessionId,
376374
completionSessionResult: {
@@ -383,6 +381,7 @@ ${itemLog}
383381
}
384382
this.languageClient.sendNotification(this.logSessionResultMessageName, params)
385383
this.sessionManager.clear()
384+
logstr += `- cursor moved behind trigger position. Discarding suggestion...`
386385
return []
387386
}
388387

@@ -410,9 +409,7 @@ ${itemLog}
410409
// Check if Next Edit Prediction feature flag is enabled
411410
if (Experiments.instance.get('amazonqLSPNEP', true)) {
412411
await showEdits(item, editor, session, this.languageClient, this)
413-
const t3 = performance.now()
414-
logstr = logstr + `- duration since trigger to NEP suggestion is displayed: ${t3 - t0}ms`
415-
this.logger.info(logstr)
412+
logstr += `- duration between trigger to edits suggestion is displayed: ${performance.now() - t0}ms`
416413
}
417414
return []
418415
}
@@ -438,9 +435,6 @@ ${itemLog}
438435

439436
// report discard if none of suggestions match typeahead
440437
if (itemsMatchingTypeahead.length === 0) {
441-
getLogger().debug(
442-
`Suggestion does not match user typeahead from insertion position. Discarding suggestion...`
443-
)
444438
const params: LogInlineCompletionSessionResultsParams = {
445439
sessionId: session.sessionId,
446440
completionSessionResult: {
@@ -453,17 +447,21 @@ ${itemLog}
453447
}
454448
this.languageClient.sendNotification(this.logSessionResultMessageName, params)
455449
this.sessionManager.clear()
450+
logstr += `- suggestion does not match user typeahead from insertion position. Discarding suggestion...`
456451
return []
457452
}
458453

459454
this.sessionManager.updateCodeReferenceAndImports()
460455
// suggestions returned here will be displayed on screen
456+
logstr += `- duration between trigger to completion suggestion is displayed: ${performance.now() - t0}ms`
461457
return itemsMatchingTypeahead as InlineCompletionItem[]
462458
} catch (e) {
463459
getLogger('amazonqLsp').error('Failed to provide completion items: %O', e)
460+
logstr += `- failed to provide completion items ${(e as Error).message}`
464461
return []
465462
} finally {
466463
vsCodeState.isRecommendationsActive = false
464+
this.logger.info(logstr)
467465
}
468466
}
469467
}

packages/amazonq/src/app/inline/recommendationService.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@ export class RecommendationService {
9292
nextToken: request.partialResultToken,
9393
},
9494
})
95+
const t0 = performance.now()
9596
const result: InlineCompletionListWithReferences = await languageClient.sendRequest(
9697
inlineCompletionWithReferencesRequestType.method,
9798
request,
9899
token
99100
)
100-
getLogger().info('Received inline completion response: %O', {
101+
getLogger().info('Received inline completion response from LSP: %O', {
101102
sessionId: result.sessionId,
103+
latency: performance.now() - t0,
102104
itemCount: result.items?.length || 0,
103105
items: result.items?.map((item) => ({
104106
itemId: item.itemId,
@@ -128,6 +130,7 @@ export class RecommendationService {
128130

129131
const isInlineEdit = result.items.some((item) => item.isInlineEdit)
130132

133+
// TODO: question, is it possible that the first request returns empty suggestion but has non-empty next token?
131134
if (result.partialResultToken) {
132135
if (!isInlineEdit) {
133136
// If the suggestion is COMPLETIONS and there are more results to fetch, handle them in the background

packages/amazonq/src/app/inline/tutorials/inlineTutorialAnnotation.ts

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@
55

66
import * as vscode from 'vscode'
77
import * as os from 'os'
8-
import {
9-
AnnotationChangeSource,
10-
AuthUtil,
11-
inlinehintKey,
12-
runtimeLanguageContext,
13-
TelemetryHelper,
14-
} from 'aws-core-vscode/codewhisperer'
8+
import { AnnotationChangeSource, AuthUtil, inlinehintKey, runtimeLanguageContext } from 'aws-core-vscode/codewhisperer'
159
import { editorUtilities, getLogger, globals, setContext, vscodeUtilities } from 'aws-core-vscode/shared'
1610
import { LinesChangeEvent, LineSelection, LineTracker } from '../stateTracker/lineTracker'
1711
import { telemetry } from 'aws-core-vscode/telemetry'
@@ -296,28 +290,27 @@ export class InlineTutorialAnnotation implements vscode.Disposable {
296290
}
297291

298292
async triggered(triggerType: vscode.InlineCompletionTriggerKind): Promise<void> {
299-
await telemetry.withTraceId(async () => {
300-
if (!this._isReady) {
301-
return
302-
}
303-
304-
if (this._currentState instanceof ManualtriggerState) {
305-
if (
306-
triggerType === vscode.InlineCompletionTriggerKind.Invoke &&
307-
this._currentState.hasManualTrigger === false
308-
) {
309-
this._currentState.hasManualTrigger = true
310-
}
311-
if (
312-
this.sessionManager.getActiveRecommendation().length > 0 &&
313-
this._currentState.hasValidResponse === false
314-
) {
315-
this._currentState.hasValidResponse = true
316-
}
317-
}
318-
319-
await this.refresh(vscode.window.activeTextEditor, 'codewhisperer')
320-
}, TelemetryHelper.instance.traceId)
293+
// TODO: this logic will take ~200ms each trigger, need to root cause and re-enable once it's fixed, or it should only be invoked when the tutorial is actually needed
294+
// await telemetry.withTraceId(async () => {
295+
// if (!this._isReady) {
296+
// return
297+
// }
298+
// if (this._currentState instanceof ManualtriggerState) {
299+
// if (
300+
// triggerType === vscode.InlineCompletionTriggerKind.Invoke &&
301+
// this._currentState.hasManualTrigger === false
302+
// ) {
303+
// this._currentState.hasManualTrigger = true
304+
// }
305+
// if (
306+
// this.sessionManager.getActiveRecommendation().length > 0 &&
307+
// this._currentState.hasValidResponse === false
308+
// ) {
309+
// this._currentState.hasValidResponse = true
310+
// }
311+
// }
312+
// await this.refresh(vscode.window.activeTextEditor, 'codewhisperer')
313+
// }, TelemetryHelper.instance.traceId)
321314
}
322315

323316
isTutorialDone(): boolean {

0 commit comments

Comments
 (0)