From 7bf82ef7575b9ce8f9c9c5887fe4db499f84c8dc Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sat, 14 Sep 2024 04:34:43 +0900 Subject: [PATCH] Making improvements to code --- .../experimentation/FeatureFlagProvider.ts | 2 +- .../src/completions/artificial-delay.test.ts | 273 +++++++++++------- vscode/src/completions/artificial-delay.ts | 34 ++- .../completions/completion-provider-config.ts | 9 + .../inline-completion-item-provider.ts | 33 ++- 5 files changed, 236 insertions(+), 115 deletions(-) diff --git a/lib/shared/src/experimentation/FeatureFlagProvider.ts b/lib/shared/src/experimentation/FeatureFlagProvider.ts index 209328dfa9ee..65bc648443e4 100644 --- a/lib/shared/src/experimentation/FeatureFlagProvider.ts +++ b/lib/shared/src/experimentation/FeatureFlagProvider.ts @@ -40,7 +40,7 @@ export enum FeatureFlag { CodyAutocompleteFIMModelExperimentVariant2 = 'cody-autocomplete-fim-model-experiment-variant-2-v2', CodyAutocompleteFIMModelExperimentVariant3 = 'cody-autocomplete-fim-model-experiment-variant-3-v2', CodyAutocompleteFIMModelExperimentVariant4 = 'cody-autocomplete-fim-model-experiment-variant-4-v2', - + CodyCompletionDisableLowPerfLangDelay = 'cody-completion-disable-low-perf-lang-delay', // Enables Claude 3 if the user is in our holdout group CodyAutocompleteClaude3 = 'cody-autocomplete-claude-3', // Enable latency adjustments based on accept/reject streaks diff --git a/vscode/src/completions/artificial-delay.test.ts b/vscode/src/completions/artificial-delay.test.ts index 94f8b824b0f3..9e59f8d821c2 100644 --- a/vscode/src/completions/artificial-delay.test.ts +++ b/vscode/src/completions/artificial-delay.test.ts @@ -1,7 +1,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { getArtificialDelay, lowPerformanceLanguageIds, resetArtificialDelay } from './artificial-delay' - const featureFlags = { user: true, } @@ -10,158 +9,218 @@ describe('getArtificialDelay', () => { beforeEach(() => { vi.useFakeTimers() }) + afterEach(() => { vi.restoreAllMocks() resetArtificialDelay() }) - it('returns gradually increasing latency up to max for CSS when suggestions are rejected', () => { + it('returns no artificial delay when codyCompletionDisableLowPerfLangDelay is true for a low performance language', async () => { const uri = 'file://foo/bar/test.css' + const codyCompletionDisableLowPerfLangDelay = true // css is a low performance language const languageId = 'css' expect(lowPerformanceLanguageIds.has(languageId)).toBe(true) + const params = { + featureFlags, + uri, + languageId, + codyCompletionDisableLowPerfLangDelay, + } + + // expect no artificial delay when codyCompletionDisableLowPerfLangDelay is true + expect(getArtificialDelay(params)).toBe(0) + }) + it('returns gradually increasing latency up to max for CSS when suggestions are rejected', async () => { + const uri = 'file://foo/bar/test.css' + + // css is a low performance language + const languageId = 'css' + expect(lowPerformanceLanguageIds.has(languageId)).toBe(true) + const codyCompletionDisableLowPerfLangDelay = false + const params = { + featureFlags, + uri, + languageId, + codyCompletionDisableLowPerfLangDelay, + } // start with default high latency for low performance lang with default user latency added - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) // start at default, but gradually increasing latency after 5 rejected suggestions - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1050) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1100) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1150) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1200) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1250) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1300) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1350) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1400) + expect(getArtificialDelay(params)).toBe(1050) + expect(getArtificialDelay(params)).toBe(1100) + expect(getArtificialDelay(params)).toBe(1150) + expect(getArtificialDelay(params)).toBe(1200) + expect(getArtificialDelay(params)).toBe(1250) + expect(getArtificialDelay(params)).toBe(1300) + expect(getArtificialDelay(params)).toBe(1350) + expect(getArtificialDelay(params)).toBe(1400) // max latency at 1400 - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1400) + expect(getArtificialDelay(params)).toBe(1400) // after the suggestion was accepted, user latency resets to 0, using baseline only resetArtificialDelay() - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) resetArtificialDelay() - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) // gradually increasing latency after 5 rejected suggestions - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1050) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1100) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1150) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1200) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1250) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1300) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1350) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1400) + expect(getArtificialDelay(params)).toBe(1050) + expect(getArtificialDelay(params)).toBe(1100) + expect(getArtificialDelay(params)).toBe(1150) + expect(getArtificialDelay(params)).toBe(1200) + expect(getArtificialDelay(params)).toBe(1250) + expect(getArtificialDelay(params)).toBe(1300) + expect(getArtificialDelay(params)).toBe(1350) + expect(getArtificialDelay(params)).toBe(1400) // Latency will not reset before 5 minutes vi.advanceTimersByTime(3 * 60 * 1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1400) + expect(getArtificialDelay(params)).toBe(1400) // Latency will be reset after 5 minutes vi.advanceTimersByTime(5 * 60 * 1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) // reset latency on accepted suggestion resetArtificialDelay() - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) }) - it('returns increasing latency after rejecting suggestions', () => { + it('returns increasing latency after rejecting suggestions', async () => { const uri = 'file://foo/bar/test.ts' // Confirm typescript is not a low performance language const languageId = 'typescript' - expect(lowPerformanceLanguageIds.has(languageId)).toBe(false) + const codyCompletionDisableLowPerfLangDelay = false + expect(lowPerformanceLanguageIds.has(languageId)).toBe(codyCompletionDisableLowPerfLangDelay) + const params = { + featureFlags, + uri, + languageId, + codyCompletionDisableLowPerfLangDelay, + } // start at default, but gradually increasing latency after 5 rejected suggestions - expect(getArtificialDelay(featureFlags, uri, languageId, 'arguments')).toBe(0) - expect(getArtificialDelay(featureFlags, uri, languageId, 'function.body')).toBe(0) + expect( + getArtificialDelay({ + ...params, + completionIntent: 'arguments', + }) + ).toBe(0) + expect( + getArtificialDelay({ + ...params, + completionIntent: 'function.body', + }) + ).toBe(0) // baseline latency increased to 1000 due to comment node type - expect(getArtificialDelay(featureFlags, uri, languageId, 'comment')).toBe(1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(0) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(0) + expect( + getArtificialDelay({ + ...params, + completionIntent: 'comment', + }) + ).toBe(1000) + expect(getArtificialDelay(params)).toBe(0) + expect(getArtificialDelay(params)).toBe(0) // gradually increasing latency after 5 rejected suggestions - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(50) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(100) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(150) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(200) + expect(getArtificialDelay(params)).toBe(50) + expect(getArtificialDelay(params)).toBe(100) + expect(getArtificialDelay(params)).toBe(150) + expect(getArtificialDelay(params)).toBe(200) // after the suggestion was accepted, user latency resets to 0, using baseline only resetArtificialDelay() - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(0) + expect(getArtificialDelay(params)).toBe(0) }) - it('returns default latency for CSS after accepting suggestion and resets after 5 minutes', () => { + it('returns default latency for CSS after accepting suggestion and resets after 5 minutes', async () => { const uri = 'file://foo/bar/test.css' // css is a low performance language const languageId = 'css' expect(lowPerformanceLanguageIds.has(languageId)).toBe(true) - + const codyCompletionDisableLowPerfLangDelay = false + const params = { + featureFlags, + uri, + languageId, + codyCompletionDisableLowPerfLangDelay, + } // start with default baseline latency for low performance lang - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) // reset to starting point on every accepted suggestion resetArtificialDelay() - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) resetArtificialDelay() - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) // Latency will not reset before 5 minutes vi.advanceTimersByTime(3 * 60 * 1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1050) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1050) // Latency will be reset after 5 minutes vi.advanceTimersByTime(5 * 60 * 1000) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) }) - it('returns increasing latency up to max after rejecting multiple suggestions, resets after file change and accept', () => { + it('returns increasing latency up to max after rejecting multiple suggestions, resets after file change and accept', async () => { const uri = 'file://foo/bar/test.ts' const languageId = 'typescript' - expect(lowPerformanceLanguageIds.has(languageId)).toBe(false) - + const codyCompletionDisableLowPerfLangDelay = false + expect(lowPerformanceLanguageIds.has(languageId)).toBe(codyCompletionDisableLowPerfLangDelay) + const params = { + featureFlags, + uri, + languageId, + codyCompletionDisableLowPerfLangDelay, + } // reject the first 5 suggestions, and confirm latency remains unchanged - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(0) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(0) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(0) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(0) - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(0) + expect(getArtificialDelay(params)).toBe(0) + expect(getArtificialDelay(params)).toBe(0) + expect(getArtificialDelay(params)).toBe(0) + expect(getArtificialDelay(params)).toBe(0) + expect(getArtificialDelay(params)).toBe(0) // latency should start increasing after 5 rejections, but max at 1400 - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(50) + expect(getArtificialDelay(params)).toBe(50) // line is a comment, so latency should be increased where: // base is 1000 due to line is a comment, and user latency is 400 as this is the 7th rejection - expect(getArtificialDelay(featureFlags, uri, languageId, 'comment')).toBe(1100) + expect(getArtificialDelay({ ...params, completionIntent: 'comment' })).toBe(1100) for (let i = 150; i <= 1400; i += 50) { - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(i) + expect(getArtificialDelay(params)).toBe(i) } // max at 1400 after multiple rejection - expect(getArtificialDelay(featureFlags, uri, languageId)).toBe(1400) + expect(getArtificialDelay(params)).toBe(1400) // reset latency on file change to default const newUri = 'foo/test.ts' // latency should start increasing again after 5 rejections - expect(getArtificialDelay(featureFlags, newUri, languageId)).toBe(0) - expect(getArtificialDelay(featureFlags, newUri, languageId)).toBe(0) + expect(getArtificialDelay({ ...params, uri: newUri })).toBe(0) + expect(getArtificialDelay({ ...params, uri: newUri })).toBe(0) // line is a comment, so latency should be increased - expect(getArtificialDelay(featureFlags, newUri, languageId, 'comment')).toBe(1000) - expect(getArtificialDelay(featureFlags, newUri, languageId)).toBe(0) - expect(getArtificialDelay(featureFlags, newUri, languageId)).toBe(0) + expect(getArtificialDelay({ ...params, uri: newUri, completionIntent: 'comment' })).toBe(1000) + expect(getArtificialDelay({ ...params, uri: newUri })).toBe(0) + expect(getArtificialDelay({ ...params, uri: newUri })).toBe(0) // Latency will not reset before 5 minutes vi.advanceTimersByTime(3 * 60 * 1000) - expect(getArtificialDelay(featureFlags, newUri, languageId)).toBe(50) + expect(getArtificialDelay({ ...params, uri: newUri })).toBe(50) // reset latency on accepted suggestion resetArtificialDelay() - expect(getArtificialDelay(featureFlags, newUri, languageId)).toBe(0) + expect(getArtificialDelay({ ...params, uri: newUri })).toBe(0) }) - it('returns default latency for low performance language only when only language flag is enabled', () => { + it('returns default latency for low performance language only when only language flag is enabled', async () => { const uri = 'file://foo/bar/test.css' + const codyCompletionDisableLowPerfLangDelay = false const featureFlagsLangOnly = { - user: false, + user: codyCompletionDisableLowPerfLangDelay, } // css is a low performance language @@ -171,46 +230,66 @@ describe('getArtificialDelay', () => { // go is not a low performance language const languageId = 'go' const goUri = 'foo/bar/test.go' - expect(lowPerformanceLanguageIds.has(languageId)).toBe(false) + expect(lowPerformanceLanguageIds.has(languageId)).toBe(codyCompletionDisableLowPerfLangDelay) + const params = { + featureFlags: featureFlagsLangOnly, + uri, + languageId, + codyCompletionDisableLowPerfLangDelay, + } // latency should only change based on language id when only the language flag is enabled - expect(getArtificialDelay(featureFlagsLangOnly, uri, lowPerformLanguageId)).toBe(1000) - expect(getArtificialDelay(featureFlagsLangOnly, uri, lowPerformLanguageId)).toBe(1000) - expect(getArtificialDelay(featureFlagsLangOnly, uri, lowPerformLanguageId)).toBe(1000) - expect(getArtificialDelay(featureFlagsLangOnly, uri, lowPerformLanguageId)).toBe(1000) - expect(getArtificialDelay(featureFlagsLangOnly, uri, lowPerformLanguageId)).toBe(1000) - expect(getArtificialDelay(featureFlagsLangOnly, uri, lowPerformLanguageId)).toBe(1000) + expect(getArtificialDelay({ ...params, languageId: lowPerformLanguageId })).toBe(1000) + expect(getArtificialDelay({ ...params, languageId: lowPerformLanguageId })).toBe(1000) + expect(getArtificialDelay({ ...params, languageId: lowPerformLanguageId })).toBe(1000) + expect(getArtificialDelay({ ...params, languageId: lowPerformLanguageId })).toBe(1000) + expect(getArtificialDelay({ ...params, languageId: lowPerformLanguageId })).toBe(1000) + expect(getArtificialDelay({ ...params, languageId: lowPerformLanguageId })).toBe(1000) // latency back to 0 when language is no longer low-performance - expect(getArtificialDelay(featureFlagsLangOnly, goUri, languageId)).toBe(0) + expect(getArtificialDelay({ ...params, uri: goUri, languageId })).toBe(0) }) - it('returns latency based on language only when user flag is disabled', () => { + it('returns latency based on language only when user flag is disabled', async () => { const uri = 'file://foo/bar/test.css' // css is a low performance language const languageId = 'css' + const codyCompletionDisableLowPerfLangDelay = false expect(lowPerformanceLanguageIds.has(languageId)).toBe(true) const featureFlagsNoUser = { - user: false, + user: codyCompletionDisableLowPerfLangDelay, + } + + const params = { + featureFlags: featureFlagsNoUser, + uri, + languageId, + codyCompletionDisableLowPerfLangDelay, } // latency starts with language latency - expect(getArtificialDelay(featureFlagsNoUser, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlagsNoUser, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlagsNoUser, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlagsNoUser, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlagsNoUser, uri, languageId)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) // latency should remains unchanged after 5 rejections - expect(getArtificialDelay(featureFlagsNoUser, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlagsNoUser, uri, languageId)).toBe(1000) - expect(getArtificialDelay(featureFlagsNoUser, uri, languageId)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) + expect(getArtificialDelay(params)).toBe(1000) // switch to a non-low-performance language - go is not a low performance language const goLanguageId = 'go' const goUri = 'foo/bar/test.go' - expect(lowPerformanceLanguageIds.has(goLanguageId)).toBe(false) + expect(lowPerformanceLanguageIds.has(goLanguageId)).toBe(codyCompletionDisableLowPerfLangDelay) // reset to provider latency because language latency is ignored for non-low-performance languages - expect(getArtificialDelay(featureFlagsNoUser, goUri, goLanguageId)).toBe(0) + const goParams = { + featureFlags: featureFlagsNoUser, + uri: goUri, + languageId: goLanguageId, + codyCompletionDisableLowPerfLangDelay, + } + expect(getArtificialDelay(goParams)).toBe(0) }) }) diff --git a/vscode/src/completions/artificial-delay.ts b/vscode/src/completions/artificial-delay.ts index 151e342b78c2..5c4377c7a035 100644 --- a/vscode/src/completions/artificial-delay.ts +++ b/vscode/src/completions/artificial-delay.ts @@ -1,6 +1,5 @@ import { logDebug } from '../log' import type { CompletionIntent } from '../tree-sitter/queries' - export interface LatencyFeatureFlags { user?: boolean } @@ -39,22 +38,37 @@ let userMetrics = { uri: '', } -// Adjust the minimum latency based on user actions and env Start when the last 5 suggestions were -// not accepted Increment latency by 200ms linearly up to max latency Reset every 5 minutes, or on -// file change, or on accepting a suggestion -export function getArtificialDelay( - featureFlags: LatencyFeatureFlags, - uri: string, - languageId: string, +/** + * Calculates the artificial delay to be added to code completion suggestions based on various factors. + * + * The delay is calculated based on the following: + * - A baseline delay for low-performance languages or completion intents + * - The user's current latency, which increases linearly up to a maximum after 5 rejected suggestions + * - The session timestamp, which is reset every 5 minutes or on file change + * + * The function returns the total delay to be added, which is capped at a maximum value. + */ +export function getArtificialDelay(params: { + featureFlags: LatencyFeatureFlags + uri: string + languageId: string + codyCompletionDisableLowPerfLangDelay: boolean completionIntent?: CompletionIntent -): number { +}): number { + const { featureFlags, uri, languageId, codyCompletionDisableLowPerfLangDelay, completionIntent } = + params + let baseline = 0 const isLowPerformanceLanguageId = lowPerformanceLanguageIds.has(languageId) const isLowPerformanceCompletionIntent = completionIntent && lowPerformanceCompletionIntents.has(completionIntent) + // Add a baseline latency for low performance languages if (isLowPerformanceLanguageId || isLowPerformanceCompletionIntent) { - baseline = defaultLatencies.lowPerformance + // if user has disabled low perf lang delay, then don't add latency + if (!codyCompletionDisableLowPerfLangDelay) { + baseline = defaultLatencies.lowPerformance + } } const timestamp = Date.now() diff --git a/vscode/src/completions/completion-provider-config.ts b/vscode/src/completions/completion-provider-config.ts index 9ea71e265375..5bb2ba969378 100644 --- a/vscode/src/completions/completion-provider-config.ts +++ b/vscode/src/completions/completion-provider-config.ts @@ -42,6 +42,7 @@ class CompletionProviderConfig { FeatureFlag.CodyAutocompletePreloadingExperimentVariant1, FeatureFlag.CodyAutocompletePreloadingExperimentVariant2, FeatureFlag.CodyAutocompletePreloadingExperimentVariant3, + FeatureFlag.CodyCompletionDisableLowPerfLangDelay, ] await Promise.all(featureFlagsUsed.map(flag => featureFlagProvider.evaluateFeatureFlag(flag))) } @@ -193,6 +194,14 @@ class CompletionProviderConfig { distinctUntilChanged() ) } + + public get completionDisableLowPerfLangDelay(): Observable { + return featureFlagProvider + .evaluatedFeatureFlag(FeatureFlag.CodyCompletionDisableLowPerfLangDelay) + .pipe( + distinctUntilChanged() + ) + } } /** diff --git a/vscode/src/completions/inline-completion-item-provider.ts b/vscode/src/completions/inline-completion-item-provider.ts index 449fb9997a23..b33917a3583f 100644 --- a/vscode/src/completions/inline-completion-item-provider.ts +++ b/vscode/src/completions/inline-completion-item-provider.ts @@ -9,6 +9,7 @@ import { contextFiltersProvider, createDisposables, featureFlagProvider, + firstValueFrom, subscriptionDisposable, telemetryRecorder, wrapInActiveSpan, @@ -123,6 +124,7 @@ export class InlineCompletionItemProvider private get config(): InlineCompletionItemProviderConfig { return InlineCompletionItemProviderConfigSingleton.configuration } + private disableLowPerfLangDelay = false constructor({ completeSuggestWidgetSelection = true, @@ -179,7 +181,23 @@ export class InlineCompletionItemProvider } this.requestManager = new RequestManager() + // Fetch the initial value for disableLowPerfLangDelay and set it + firstValueFrom(completionProviderConfig.completionDisableLowPerfLangDelay).then( + disableLowPerfLangDelay => { + this.disableLowPerfLangDelay = disableLowPerfLangDelay + } + ) + // Subscribe to changes in disableLowPerfLangDelay and update the value accordingly + this.disposables.push( + subscriptionDisposable( + completionProviderConfig.completionDisableLowPerfLangDelay.subscribe( + disableLowPerfLangDelay => { + this.disableLowPerfLangDelay = disableLowPerfLangDelay + } + ) + ) + ) const strategyFactory = new DefaultContextStrategyFactory( completionProviderConfig.contextStrategy, createBfgRetriever @@ -435,13 +453,14 @@ export class InlineCompletionItemProvider FeatureFlag.CodyAutocompleteUserLatency ), } - - const artificialDelay = getArtificialDelay( - latencyFeatureFlags, - document.uri.toString(), - document.languageId, - completionIntent - ) + const params = { + featureFlags: latencyFeatureFlags, + uri: document.uri.toString(), + languageId: document.languageId, + codyCompletionDisableLowPerfLangDelay: this.disableLowPerfLangDelay, + completionIntent: completionIntent, + } + const artificialDelay = getArtificialDelay({ ...params }) const debounceInterval = this.config.provider.mayUseOnDeviceInference ? 125 : 75 stageRecorder.record('preGetInlineCompletions')