Skip to content

Commit

Permalink
Try to reduce size of completions DTO (#164087)
Browse files Browse the repository at this point in the history
JS/TS can return a lot of completions. I noticed that just parsing this was taking a bit of time, so I tried to reduce the message size with the following changes:

- Inline the command properties on `ISuggestDataDto`
- Drop the `title` and `tooltip` from the command since we don't use these
- Shorten the delegate command name
- If using an `$ident` command, don't send over the command arguments since the arguments are always `[$ident]`
- Make commit characters a string instead of an array

Here's an example of a dto for a completion item before:

```
{"x":[2,0],"a":"$","b":4,"e":"15","i":0,"k":[".",",",";","("],"m":{"$ident":867,"id":"_vscode_delegate_cmd_l9g7z48t","title":"","arguments":[867]}}
```

And after:

```
{"x":[1,0],"a":"$","b":4,"e":"15","i":0,"k":".,;(","n":11,"o":"__vsl9g7vfno"}
```

For global completions in a JS/TS file, this makes the completion response a little over 40% smaller.
  • Loading branch information
mjbvz committed Oct 24, 2022
1 parent 0c6cc3a commit a8c16a0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
12 changes: 10 additions & 2 deletions src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ export class MainThreadLanguageFeatures extends Disposable implements MainThread
private static _inflateSuggestDto(defaultRange: IRange | { insert: IRange; replace: IRange }, data: ISuggestDataDto): languages.CompletionItem {

const label = data[ISuggestDataDtoField.label];
const commandId = data[ISuggestDataDtoField.commandId];
const commandIdent = data[ISuggestDataDtoField.commandIdent];
const commitChars = data[ISuggestDataDtoField.commitCharacters];

return {
label,
Expand All @@ -485,9 +488,14 @@ export class MainThreadLanguageFeatures extends Disposable implements MainThread
insertText: data[ISuggestDataDtoField.insertText] ?? (typeof label === 'string' ? label : label.label),
range: data[ISuggestDataDtoField.range] ?? defaultRange,
insertTextRules: data[ISuggestDataDtoField.insertTextRules],
commitCharacters: data[ISuggestDataDtoField.commitCharacters],
commitCharacters: commitChars ? Array.from(commitChars) : undefined,
additionalTextEdits: data[ISuggestDataDtoField.additionalTextEdits],
command: data[ISuggestDataDtoField.command],
command: commandId ? {
$ident: commandIdent,
id: commandId,
title: '',
arguments: commandIdent ? [commandIdent] : data[ISuggestDataDtoField.commandArguments], // Automatically fill in ident as first argument
} as languages.Command : undefined,
// not-standard
_id: data.x,
};
Expand Down
13 changes: 9 additions & 4 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1547,8 +1547,10 @@ export const enum ISuggestDataDtoField {
range = 'j',
commitCharacters = 'k',
additionalTextEdits = 'l',
command = 'm',
kindModifier = 'n',
kindModifier = 'm',
commandIdent = 'n',
commandId = 'o',
commandArguments = 'p',
}

export interface ISuggestDataDto {
Expand All @@ -1562,10 +1564,13 @@ export interface ISuggestDataDto {
[ISuggestDataDtoField.insertText]?: string;
[ISuggestDataDtoField.insertTextRules]?: languages.CompletionItemInsertTextRule;
[ISuggestDataDtoField.range]?: IRange | { insert: IRange; replace: IRange };
[ISuggestDataDtoField.commitCharacters]?: string[];
[ISuggestDataDtoField.commitCharacters]?: string;
[ISuggestDataDtoField.additionalTextEdits]?: ISingleEditOperation[];
[ISuggestDataDtoField.command]?: languages.Command;
[ISuggestDataDtoField.kindModifier]?: languages.CompletionItemTag[];
// Command
[ISuggestDataDtoField.commandIdent]?: number;
[ISuggestDataDtoField.commandId]?: string;
[ISuggestDataDtoField.commandArguments]?: any[];
// not-standard
x?: ChainedCacheId;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHostCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export const IExtHostCommands = createDecorator<IExtHostCommands>('IExtHostComma

export class CommandsConverter implements extHostTypeConverter.Command.ICommandsConverter {

readonly delegatingCommandId: string = `_vscode_delegate_cmd_${Date.now().toString(36)}`;
readonly delegatingCommandId: string = `__vsc${Date.now().toString(36)}`;
private readonly _cache = new Map<number, vscode.Command>();
private _cachIdPool = 0;

Expand Down
7 changes: 5 additions & 2 deletions src/vs/workbench/api/common/extHostLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ class CompletionsAdapter {
throw Error('DisposableStore is missing...');
}

const command = this._commands.toInternal(item.command, disposables);
const result: extHostProtocol.ISuggestDataDto = {
//
x: id,
Expand All @@ -1021,9 +1022,11 @@ class CompletionsAdapter {
[extHostProtocol.ISuggestDataDtoField.filterText]: item.filterText !== item.label ? item.filterText : undefined,
[extHostProtocol.ISuggestDataDtoField.preselect]: item.preselect || undefined,
[extHostProtocol.ISuggestDataDtoField.insertTextRules]: item.keepWhitespace ? languages.CompletionItemInsertTextRule.KeepWhitespace : 0,
[extHostProtocol.ISuggestDataDtoField.commitCharacters]: item.commitCharacters,
[extHostProtocol.ISuggestDataDtoField.commitCharacters]: item.commitCharacters?.join(''),
[extHostProtocol.ISuggestDataDtoField.additionalTextEdits]: item.additionalTextEdits && item.additionalTextEdits.map(typeConvert.TextEdit.from),
[extHostProtocol.ISuggestDataDtoField.command]: this._commands.toInternal(item.command, disposables),
[extHostProtocol.ISuggestDataDtoField.commandIdent]: command?.$ident,
[extHostProtocol.ISuggestDataDtoField.commandId]: command?.id,
[extHostProtocol.ISuggestDataDtoField.commandArguments]: command?.$ident ? undefined : command?.arguments, // filled in on main side from $ident
};

// 'insertText'-logic
Expand Down

0 comments on commit a8c16a0

Please sign in to comment.