Skip to content

Commit

Permalink
add trace logging for language feature debounce rates, #140557
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jan 20, 2022
1 parent 88f0761 commit 3c601f1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
20 changes: 16 additions & 4 deletions src/vs/editor/common/services/languageFeatureDebounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { LanguageFeatureRegistry } from 'vs/editor/common/languages/languageFeat
import { ITextModel } from 'vs/editor/common/model';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';


export const ILanguageFeatureDebounceService = createDecorator<ILanguageFeatureDebounceService>('ILanguageFeatureDebounceService');
Expand All @@ -18,7 +19,7 @@ export interface ILanguageFeatureDebounceService {

readonly _serviceBrand: undefined;

for(feature: LanguageFeatureRegistry<object>, config?: { min?: number, salt?: string }): IFeatureDebounceInformation;
for(feature: LanguageFeatureRegistry<object>, debugName: string, config?: { min?: number, salt?: string }): IFeatureDebounceInformation;
}

export interface IFeatureDebounceInformation {
Expand All @@ -45,6 +46,8 @@ class FeatureDebounceInformation implements IFeatureDebounceInformation {
private readonly _cache = new LRUCache<string, SlidingWindowAverage>(50, 0.7);

constructor(
private readonly _logService: ILogService,
private readonly _name: string,
private readonly _registry: LanguageFeatureRegistry<object>,
private readonly _default: number,
private readonly _min: number,
Expand All @@ -70,7 +73,9 @@ class FeatureDebounceInformation implements IFeatureDebounceInformation {
avg = new SlidingWindowAverage(12);
this._cache.set(key, avg);
}
return clamp(avg.update(value), this._min, this._max);
const newValue = clamp(avg.update(value), this._min, this._max);
this._logService.trace(`[DEBOUNCE: ${this._name}] for ${model.uri.toString()} is ${newValue}ms`);
return newValue;
}

private _overall(): number {
Expand All @@ -94,13 +99,20 @@ export class LanguageFeatureDebounceService implements ILanguageFeatureDebounceS

private readonly _data = new Map<string, FeatureDebounceInformation>();

for(feature: LanguageFeatureRegistry<object>, config?: { min?: number, key?: string }): IFeatureDebounceInformation {
constructor(@ILogService private readonly _logService: ILogService) {

}

for(feature: LanguageFeatureRegistry<object>, name: string, config?: { min?: number, key?: string }): IFeatureDebounceInformation {
const min = config?.min ?? 50;
const extra = config?.key ?? undefined;
const key = `${IdentityHash.of(feature)},${min}${extra ? ',' + extra : ''}`;
let info = this._data.get(key);
if (!info) {
info = new FeatureDebounceInformation(feature,
info = new FeatureDebounceInformation(
this._logService,
name,
feature,
(this._overallAverage() | 0) || (min * 1.5), // default is overall default or derived from min-value
min
);
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/contrib/codelens/codelensController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export class CodeLensContribution implements IEditorContribution {
@INotificationService private readonly _notificationService: INotificationService,
@ICodeLensCache private readonly _codeLensCache: ICodeLensCache
) {
this._provideCodeLensDebounce = debounceService.for(CodeLensProviderRegistry, { min: 250 });
this._resolveCodeLensesDebounce = debounceService.for(CodeLensProviderRegistry, { min: 250, salt: 'resolve' });
this._provideCodeLensDebounce = debounceService.for(CodeLensProviderRegistry, 'CodeLensProvide', { min: 250 });
this._resolveCodeLensesDebounce = debounceService.for(CodeLensProviderRegistry, 'CodeLensResolve', { min: 250, salt: 'resolve' });
this._resolveCodeLensesScheduler = new RunOnceScheduler(() => this._resolveCodeLensesInViewport(), this._resolveCodeLensesDebounce.default());

this._disposables.add(this._editor.onDidChangeModel(() => this._onModelChange()));
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/documentSymbols/outlineModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ export class OutlineModelService implements IOutlineModelService {
@ILanguageFeatureDebounceService debounces: ILanguageFeatureDebounceService,
@IModelService modelService: IModelService
) {
this._debounceInformation = debounces.for(DocumentSymbolProviderRegistry, { min: 350 });
this._debounceInformation = debounces.for(DocumentSymbolProviderRegistry, 'DocumentSymbols', { min: 350 });

// don't cache outline models longer than their text model
this._disposables.add(modelService.onModelRemoved(textModel => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DocumentSymbol, DocumentSymbolProviderRegistry, SymbolKind } from 'vs/e
import { LanguageFeatureDebounceService } from 'vs/editor/common/services/languageFeatureDebounce';
import { IModelService } from 'vs/editor/common/services/model';
import { createModelServices, createTextModel } from 'vs/editor/test/common/testTextModel';
import { NullLogService } from 'vs/platform/log/common/log';
import { IMarker, MarkerSeverity } from 'vs/platform/markers/common/markers';
import { OutlineElement, OutlineGroup, OutlineModel, OutlineModelService } from '../outlineModel';

Expand All @@ -27,7 +28,7 @@ suite('OutlineModel', function () {

const insta = createModelServices(disposables);
const modelService = insta.get(IModelService);
const service = new OutlineModelService(new LanguageFeatureDebounceService(), modelService);
const service = new OutlineModelService(new LanguageFeatureDebounceService(new NullLogService()), modelService);

let model = createTextModel('foo', undefined, undefined, URI.file('/fome/path.foo'));
let count = 0;
Expand Down Expand Up @@ -58,7 +59,7 @@ suite('OutlineModel', function () {

const insta = createModelServices(disposables);
const modelService = insta.get(IModelService);
const service = new OutlineModelService(new LanguageFeatureDebounceService(), modelService);
const service = new OutlineModelService(new LanguageFeatureDebounceService(new NullLogService()), modelService);
let model = createTextModel('foo', undefined, undefined, URI.file('/fome/path.foo'));
let isCancelled = false;

Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/inlayHints/inlayHintsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class InlayHintsController implements IEditorContribution {
@INotificationService private readonly _notificationService: INotificationService,
@IInstantiationService private readonly _instaService: IInstantiationService,
) {
this._debounceInfo = _featureDebounce.for(languages.InlayHintsProviderRegistry, { min: 25 });
this._debounceInfo = _featureDebounce.for(languages.InlayHintsProviderRegistry, 'InlayHint', { min: 25 });
this._disposables.add(languages.InlayHintsProviderRegistry.onDidChange(() => this._update()));
this._disposables.add(_editor.onDidChangeModel(() => this._update()));
this._disposables.add(_editor.onDidChangeModelLanguage(() => this._update()));
Expand Down

0 comments on commit 3c601f1

Please sign in to comment.