Skip to content

Commit

Permalink
BugFix: fix perceivedLatency being calculated incorrectly
Browse files Browse the repository at this point in the history
The perceivedLatency is currently calculateand and sent when we send
STE, by then lastUserModificationTime is no longer accurate.
Instead calculate perceivedLatency when we show the suggestions and use
the lastUserModificationTime at that time to be accurate.
  • Loading branch information
andrewyuq committed Oct 25, 2024
1 parent 142761e commit 786c319
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ReferenceInlineProvider } from './referenceInlineProvider'
import { ImportAdderProvider } from './importAdderProvider'
import { application } from '../util/codeWhispererApplication'
import path from 'path'
import { vsCodeState } from '../indexNode'

export class CWInlineCompletionItemProvider implements vscode.InlineCompletionItemProvider {
private activeItemIndex: number | undefined
Expand Down Expand Up @@ -169,6 +170,7 @@ export class CWInlineCompletionItemProvider implements vscode.InlineCompletionIt
ImportAdderProvider.instance.onShowRecommendation(document, this.startPos.line, r)
this.nextMove = 0
TelemetryHelper.instance.setFirstSuggestionShowTime()
session.setPerceivedLatency()
this._onDidShow.fire()
if (matchedCount >= 2 || this.nextToken !== '') {
const result = [item]
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/codewhisperer/util/codeWhispererSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { GenerateRecommendationsRequest, ListRecommendationsRequest, Recommendation } from '../client/codewhisperer'
import { Position } from 'vscode'
import { CodeWhispererSupplementalContext, vsCodeState } from '../models/model'
import { resolveTransitionHooks } from 'vue'

class CodeWhispererSession {
static #instance: CodeWhispererSession
Expand Down Expand Up @@ -43,6 +44,7 @@ class CodeWhispererSession {
invokeSuggestionStartTime = 0
timeToFirstRecommendation = 0
firstSuggestionShowTime = 0
perceivedLatency = 0

public static get instance() {
return (this.#instance ??= new CodeWhispererSession())
Expand Down Expand Up @@ -91,6 +93,17 @@ class CodeWhispererSession {
}
}

setPerceivedLatency() {
if (this.perceivedLatency !== 0) {
return
}
if (this.triggerType === 'OnDemand') {
this.perceivedLatency = this.timeToFirstRecommendation
} else {
this.perceivedLatency = this.firstSuggestionShowTime - vsCodeState.lastUserModificationTime
}
}

reset() {
this.sessionId = ''
this.requestContext = { request: {} as any, supplementalMetadata: {} as any }
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/codewhisperer/util/telemetryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ export class TelemetryHelper {
suggestionState: this.getSendTelemetrySuggestionState(aggregatedSuggestionState),
recommendationLatencyMilliseconds: e2eLatency,
triggerToResponseLatencyMilliseconds: session.timeToFirstRecommendation,
perceivedLatencyMilliseconds: session.getPerceivedLatency(
this.sessionDecisions[0].codewhispererTriggerType
),
perceivedLatencyMilliseconds: session.perceivedLatency,
timestamp: new Date(Date.now()),
suggestionReferenceCount: referenceCount,
generatedLine: generatedLines,
Expand Down Expand Up @@ -388,6 +386,7 @@ export class TelemetryHelper {
this.typeAheadLength = 0
this.timeSinceLastModification = 0
session.timeToFirstRecommendation = 0
session.perceivedLatency = 0
this.classifierResult = undefined
this.classifierThreshold = undefined
}
Expand Down

0 comments on commit 786c319

Please sign in to comment.